<
UserControl
x:Class
=
"LibreriaWpfCoster.EditorSingolaVariabileInt32"
xmlns:globalization
=
"clr-namespace:System.Globalization;assembly=mscorlib"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
MinWidth
=
"40"
MinHeight
=
"20"
mc:Ignorable
=
"d"
d:DesignWidth
=
"40"
d:DesignHeight
=
"71"
Loaded
=
"UserControl_Loaded"
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"LightGreen"
AllowDrop
=
"True"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"20"
/>
<
ColumnDefinition
Width
=
"*"
/>
</
Grid.ColumnDefinitions
>
<!--Icona che cambia in funzione del tipo rilevato e cliccandoci sopra resetta la variabile-->
<
Image
x:Name
=
"imgObj"
Source
=
"Images/Numero32Negativo.png"
Stretch
=
"Uniform"
MouseLeftButtonDown
=
"imgObj_MouseLeftButtonDown"
/>
<!--Oggetto per editare il nome della variabile-->
<
TextBox
x:Name
=
"varObj"
Grid.Column
=
"1"
Panel.ZIndex
=
"0"
Text
=
"{Binding Path=PlcVar, Mode=TwoWay}"
PreviewKeyDown
=
"varObj_PreviewKeyDown"
ContextMenu
=
"{x:Null}"
/>
<!--Oggetto per editare il nome della SysVar-->
<
TextBox
x:Name
=
"varSysObj"
Grid.Column
=
"1"
Panel.ZIndex
=
"0"
Text
=
"{Binding Path=SysVarName, Mode=TwoWay}"
PreviewKeyDown
=
"varObj_PreviewKeyDown"
ContextMenu
=
"{x:Null}"
/>
</
Grid
>
</
UserControl
>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ClassiCoster;
using System.ComponentModel;
using Telerik.Windows.DragDrop;
using Telerik.Windows;
namespace LibreriaWpfCoster
{
/// <
summary
>
/// Interaction logic for EditorSingolaVariabileInt16.xaml
/// </
summary
>
public partial class EditorSingolaVariabileInt32 : UserControl
{
public EditorSingolaVariabileInt32()
{
InitializeComponent();
DragDropManager.AddDropHandler(this, OnVarDrop);
DragDropManager.AddDragOverHandler(this, OnVarDragOver);
DragDropManager.AddDragLeaveHandler(this, OnVarDragLeave);
}
/// <
summary
>
/// Variabile PLC
/// </
summary
>
public SingolaVariabileInt32 Variabile
{
get { return (SingolaVariabileInt32)GetValue(VariabileProperty); }
set { SetValue(VariabileProperty, value); }
}
public static readonly DependencyProperty VariabileProperty = DependencyProperty.Register("Variabile",
typeof(SingolaVariabileInt32),
typeof(EditorSingolaVariabileInt32),
new PropertyMetadata(new SingolaVariabileInt32(), OnVariabilePropertyChanged));
private static void OnVariabilePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as EditorSingolaVariabileInt32).LayoutRoot.DataContext = ((EditorSingolaVariabileInt32)d).Variabile;
(d as EditorSingolaVariabileInt32).MettiInPrimoPianoIlControlloCorretto();
}
private static List<
PlcVariableType
> _allowedVars = new List<
PlcVariableType
>(new PlcVariableType[]
{
PlcVariableType.INT8,
PlcVariableType.UINT8,
PlcVariableType.INT16,
PlcVariableType.UINT16,
PlcVariableType.INT32,
PlcVariableType.UINT32,
});
/// <
summary
>
/// Specifica i tipi di variabili ammessi per venir messe in binding
/// </
summary
>
public List<
PlcVariableType
> AllowedVars
{
get { return _allowedVars; }
set { _allowedVars = value; }
}
private static List<
PlcVariableType
> _allowedIndexVars = new List<
PlcVariableType
>(new PlcVariableType[]
{
PlcVariableType.INT8,
PlcVariableType.UINT8,
PlcVariableType.INT16,
PlcVariableType.UINT16,
PlcVariableType.INT32,
PlcVariableType.UINT32,
});
/// <
summary
>
/// Specifica i tipi di variabili che possono venir messe in binding per gli indici
/// </
summary
>
public List<
PlcVariableType
> AllowedIndexVars
{
get { return _allowedIndexVars; }
set { _allowedIndexVars = value; }
}
/// <
summary
>
/// Fa l'effetto per draggare una variabile
/// </
summary
>
/// <
param
name
=
"sender"
></
param
>
/// <
param
name
=
"e"
></
param
>
private void OnVarDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
Boolean Evidenzia = false;
if (e.Data is DataObject)
{
VariabilePlc vPlc = (e.Data as DataObject).GetData(typeof(VariabilePlc)) as VariabilePlc;
if (vPlc != null)
{
if (vPlc.SysVarID > 0) ProvaASelezionareUnIndice();
Evidenzia = GenericiEditorVariabili.DimmiSeAppartieneAllaLista(_allowedVars, vPlc.Tipo);
if (!Evidenzia && vPlc.SysVarID <
1
&& GenericiEditorVariabili.DimmiSeHoSelezionatoUnIndice(varObj))
{
Evidenzia
=
GenericiEditorVariabili
.DimmiSeAppartieneAllaLista(_allowedIndexVars, vPlc.Tipo);
}
}
}
e.Effects
=
Evidenzia
? DragDropEffects.Copy : DragDropEffects.None;
GenericiEditorVariabili.EvidenziaPerDrag(LayoutRoot, Evidenzia);
e.Handled
=
true
;
}
private void OnVarDragLeave(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
e.Effects
=
DragDropEffects
.None;
GenericiEditorVariabili.EvidenziaPerDrag(LayoutRoot, false);
e.Handled
=
true
;
}
/// <summary>
/// Viene eseguito al drop di una variabile
/// </
summary
>
/// <
param
name
=
"sender"
></
param
>
/// <
param
name
=
"e"
></
param
>
private void OnVarDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
GenericiEditorVariabili.EvidenziaPerDrag(LayoutRoot, false);
if (e.Data == null || !(e.Data is DataObject)) return;
VariabilePlc vPlc = (e.Data as DataObject).GetData(typeof(VariabilePlc)) as VariabilePlc;
if (vPlc != null)
{
ProvaASelezionareUnIndice();
if (vPlc.SysVarID <
1
&& GenericiEditorVariabili.DimmiSeHoSelezionatoUnIndice(varObj))
{
if (GenericiEditorVariabili.DimmiSeAppartieneAllaLista(_allowedIndexVars, vPlc.Tipo))
{
String
strPrima
=
varObj
.Text.Substring(0, varObj.SelectionStart);
String
strDopo
=
varObj
.Text.Substring(varObj.SelectionStart + varObj.SelectionLength);
Variabile.PlcVar
=
strPrima
+ vPlc.PlcVar + strDopo;
}
else
{
if (GenericiEditorVariabili.DimmiSeAppartieneAllaLista(_allowedVars, vPlc.Tipo))
{
Variabile.ResetVar();
Variabile.PlcVar
=
vPlc
.PlcVar;
}
}
}
else
{
if (GenericiEditorVariabili.DimmiSeAppartieneAllaLista(_allowedVars, vPlc.Tipo))
{
Variabile.ResetVar();
if (vPlc.SysVarID > 0)
{
Variabile.SysVarName = vPlc.PlcVar;
Variabile.SysVarID = vPlc.SysVarID;
}
else
{
Variabile.PlcVar = vPlc.PlcVar;
}
}
}
MettiInPrimoPianoIlControlloCorretto();
e.Handled = true;
}
}
//private void OnDropQuery(object sender, DragDropQueryEventArgs e)
//{
// switch (e.Options.Status)
// {
// case DragStatus.DropDestinationQuery:
// if (e.Options.Payload is VariabilePlc)
// {
// VariabilePlc vPlc = e.Options.Payload as VariabilePlc;
// if (GenericiEditorVariabili.DimmiSeAppartieneAllaLista(_allowedVars, vPlc.Tipo) ||
// (vPlc.SysVarID <
1
&& GenericiEditorVariabili.DimmiSeAppartieneAllaLista(_allowedIndexVars, vPlc.Tipo))
// )
// {
//
e.QueryResult
=
true
;
//
e.Handled
=
true
;
// }
// }
// break;
// }
//}
//private void OnDropInfo(object sender, DragDropEventArgs e)
//{
// LibreriaWpfCoster.CustomDragCue
cueObj
= e.Options.DragCue as LibreriaWpfCoster.CustomDragCue;
// if (e.Options.Status == DragStatus.DropPossible) GenericiEditorVariabili.EvidenziaPerDrag(LayoutRoot,cueObj , true);
// if (e.Options.Status == DragStatus.DropImpossible) GenericiEditorVariabili.EvidenziaPerDrag(LayoutRoot,cueObj , false);
// if (e.Options.Status != DragStatus.DropComplete) return;
// GenericiEditorVariabili.EvidenziaPerDrag(LayoutRoot,cueObj, false);
// VariabilePlc
vPlc
=
e
.Options.Payload as VariabilePlc;
// if (e.Options.Status == DragStatus.DropComplete && vPlc != null)
// {
// ProvaASelezionareUnIndice();
// if (vPlc.SysVarID < 1 && GenericiEditorVariabili.DimmiSeHoSelezionatoUnIndice(varObj))
// {
// if (GenericiEditorVariabili.DimmiSeAppartieneAllaLista(_allowedIndexVars, vPlc.Tipo))
// {
// String
strPrima
=
varObj
.Text.Substring(0, varObj.SelectionStart);
// String
strDopo
=
varObj
.Text.Substring(varObj.SelectionStart + varObj.SelectionLength);
//
Variabile.PlcVar
=
strPrima
+ vPlc.PlcVar + strDopo;
// }
// else
// {
// if (GenericiEditorVariabili.DimmiSeAppartieneAllaLista(_allowedVars, vPlc.Tipo))
// {
// Variabile.ResetVar();
//
Variabile.PlcVar
=
vPlc
.PlcVar;
// }
// }
// }
// else
// {
// if (GenericiEditorVariabili.DimmiSeAppartieneAllaLista(_allowedVars, vPlc.Tipo))
// {
// Variabile.ResetVar();
// if (vPlc.SysVarID > 0)
// {
// Variabile.SysVarName = vPlc.PlcVar;
// Variabile.SysVarID = vPlc.SysVarID;
// }
// else
// {
// Variabile.PlcVar = vPlc.PlcVar;
// }
// }
// }
// MettiInPrimoPianoIlControlloCorretto();
// e.Handled = true;
// }
//}
/// <
summary
>
/// Partendo dalla posizione del cursore prova a vedere se nell'intorno c'è un array
/// </
summary
>
private void ProvaASelezionareUnIndice()
{
int PosParentesiSinistra, PosParentesiDestra;
if (varObj.Text.Length <
4
|| varObj.SelectionStart < 1) return;
if (varObj.SelectionStart >= varObj.Text.Length) return;
if (",".IndexOf(varObj.Text.Substring(varObj.SelectionStart, 1)) != -1) varObj.SelectionStart++;
for (PosParentesiSinistra = varObj.SelectionStart; PosParentesiSinistra > 1; PosParentesiSinistra--)
{
if ("[,".IndexOf(varObj.Text.Substring(PosParentesiSinistra, 1)) != -1)
{
break;
}
}
for (PosParentesiDestra = varObj.SelectionStart; PosParentesiDestra <
varObj.Text.Length
; PosParentesiDestra++)
{
if (",]".IndexOf(varObj.Text.Substring(PosParentesiDestra, 1)) != -1)
{
break;
}
}
if (PosParentesiSinistra > 0 && (PosParentesiDestra <
varObj.Text.Length
))
{
varObj.SelectionStart
=
PosParentesiSinistra
+ 1;
varObj.SelectionLength
=
PosParentesiDestra
- PosParentesiSinistra - 1;
}
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
LayoutRoot.DataContext
=
Variabile
;
MettiInPrimoPianoIlControlloCorretto();
varObj.ContextMenu
=
null
;
}
private void MettiInPrimoPianoIlControlloCorretto()
{
Int32
varObjZ
=
0
;
Int32
varSysObjZ
=
0
;
if (Variabile.SysVarID > 0)
{
varSysObjZ = 1;
}
else
{
varObjZ = 1;
}
varObj.SetValue(Panel.ZIndexProperty, varObjZ);
varSysObj.SetValue(Panel.ZIndexProperty, varSysObjZ);
}
/// <
summary
>
/// Ho gestito quest'evento per aggiornare in caso di testo vuoto
/// </
summary
>
/// <
param
name
=
"sender"
></
param
>
/// <
param
name
=
"e"
></
param
>
private void varObj_PreviewKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
case Key.Back:
case Key.Delete:
Variabile.ResetVar();
MettiInPrimoPianoIlControlloCorretto();
break;
default:
break;
}
e.Handled = true;
}
/// <
summary
>
/// Serve per cancellare la variabile plc se gli si clicca sopra
/// </
summary
>
/// <
param
name
=
"sender"
></
param
>
/// <
param
name
=
"e"
></
param
>
private void imgObj_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Variabile.ResetVar();
MettiInPrimoPianoIlControlloCorretto();
e.Handled = true;
}
}
}
Hi,
Since we’ve encountered your new RadMaskedInput controls and realized, that these are the replacement of your RadMaskedTextBox (they are, aren’t they?), we didn’t find any reason for this update. Even worse, we are about to use your old RadMaskedTextBox on.
We mostly use your input controls for non-restricted text or non-restricted numeric values. In those cases we expect an input behavior like a normal TextBox got. More precisely, inputs a user enters shouldn’t replace old characters just because the mask restricts the length of the characters. The input, a user does should be just inserted at the caret’s position, without replacing.
The other problem, we’ve ran into is the following: We’ve bound a string value to the Value property of a RadMaskedTextInput control. This control has a mask of 20 optional alphanumeric characters (Mask=”a20”). Now when moving the caret at a different position then the beginning, the entered text would be saved without leading whitespaces. That’s a behavior which no user would expect.
Using your old input control, we didn’t run into all this trouble. I don’t think that there are many developers, who are used to your old Input Control, like the new ones. I don’t understand why you’ve replaced good working controls with these weak components.
I would recommend you to provide just one suite of input controls, which really work and which offers a way to be less restrictive.
Best,
Martin
<telerik:RadOutlookBar.ContentTemplate>
<DataTemplate>
<ContentControl Content="{Binding ActiveBar}"/>
</DataTemplate>
</telerik:RadOutlookBar.ContentTemplate>
[CanConvert(
typeof
(System.String),
typeof
(System.Nullable<
double
>))]
public
class
StringToNullableDouble : IValueConverter
{
public
object
Convert(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
string
s = value
as
string
;
if
(s ==
null
)
return
null
;
double
d;
if
(Double.TryParse(s,
out
d))
return
d;
return
null
;
}
public
object
ConvertBack(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
double
? d = value
as
double
?;
if
(d ==
null
|| !d.HasValue)
return
null
;
return
d.Value.ToString();
}
}
<
tel:RadMaskedNumericInput
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Center"
EmptyContent
=
"Enter Phone"
Width
=
"120"
Margin
=
"2"
Mask
=
"(###) ###-####"
Value
=
"{Binding Path=Customer.Phone, ValidatesOnDataErrors=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
FontWeight
=
"Bold"
AllowInvalidValues
=
"False"
AutoFillNumberGroupSeparators
=
false
;
AutoFillZeros
=
"False"
FlowDirection
=
"LeftToRight"
Precision
=
"0"
HorizontalContentAlignment
=
"Left"
TextMode
=
"MaskedText"
SpinMode
=
"None"
/>
<
telerik:LineSeries
Stroke
=
"#FF51B0DD"
StrokeThickness
=
"2"
Opacity
=
"0.6"
/>
<StackPanel Margin="3">
<telerik:RadRibbonButton SmallImage="Images/16/Cut.png" Text="Cut" Command="Cut"/>
<telerik:Separator />
<telerik:RadRibbonButton SmallImage="Images/16/Copy.png" Text="Copy" Command="Copy" />
</StackPanel>
The panel is in a Ribbon group, itself in a Ribbon Tab.
The Separator does not show in the Visual Studio Editor (it is selectable but not visisble) and it does not show at run time.
Giving the Separator a width and height makes it visible at design time but not at design time.
Any help will be appreciated