This question is locked. New answers and comments are not allowed.
Hello,
I have one problem with bindings in NumericUpDown editor. Code first:
Xaml:
Code behind:
Entity.cs:
I'm trying to bind control DpDecimal to DefaultValue of an entity. I have also some properties of the default value like precision, scale,..
The control DpDecimal has bound its properties NumberDecimalDigits, Minimum, Maximum to controls of these properties. I have also one help button here and when click to this button the actual value of entity default value is filled into the textbox next to it, just for testing.
I'm trying this scenario:
I need somehow to fix this to have changed also the value of the property in the entity. I also need to keep default value as a string because of the structure of my application. I did try to handle events from property controls and update the control of default value source explicitly but it also doesn't work. Neither change of UpdateEvent to PropertyChanged help.
Thanks for any advice.
I have one problem with bindings in NumericUpDown editor. Code first:
Xaml:
<
UserControl
x:Class
=
"SilverlightApplication.MainPage"
xmlns:telerik_pres
=
"clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
</
Grid.ColumnDefinitions
>
<
StackPanel
x:Name
=
"SpDecimal"
Grid.Row
=
"0"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
</
Grid.ColumnDefinitions
>
<
TextBlock
Grid.Row
=
"0"
Grid.Column
=
"0"
Text
=
"Default value"
/>
<
telerik_pres:RadNumericUpDown
x:Name
=
"DpDecimal"
Value
=
"{Binding Path=DefaultValue, Mode=TwoWay}"
NumberDecimalDigits
=
"{Binding ElementName=RnudDecimalScale, Path=Value}"
Minimum
=
"{Binding ElementName=RnudDecimalMin, Path=Value}"
Maximum
=
"{Binding ElementName=RnudDecimalMax, Path=Value}"
Grid.Row
=
"0"
Grid.Column
=
"1"
/>
</
Grid
>
</
StackPanel
>
<
StackPanel
x:Name
=
"SpDecimalProp"
Grid.Row
=
"1"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
</
Grid.ColumnDefinitions
>
<
TextBlock
Grid.Row
=
"0"
Grid.Column
=
"0"
Text
=
"Precision"
/>
<
telerik_pres:RadNumericUpDown
x:Name
=
"RnudDecimalPrecision"
Value
=
"{Binding Path=Precision, Mode=TwoWay}"
Grid.Row
=
"0"
Grid.Column
=
"1"
NumberDecimalDigits
=
"0"
/>
<
TextBlock
Grid.Row
=
"1"
Grid.Column
=
"0"
Text
=
"Scale"
/>
<
telerik_pres:RadNumericUpDown
x:Name
=
"RnudDecimalScale"
Value
=
"{Binding Path=Scale, Mode=TwoWay}"
Grid.Row
=
"1"
Grid.Column
=
"1"
NumberDecimalDigits
=
"0"
/>
<
TextBlock
Grid.Row
=
"2"
Grid.Column
=
"0"
Text
=
"Min"
/>
<
telerik_pres:RadNumericUpDown
x:Name
=
"RnudDecimalMin"
Value
=
"{Binding Path=Min, Mode=TwoWay}"
Grid.Row
=
"2"
Grid.Column
=
"1"
NumberDecimalDigits
=
"0"
/>
<
TextBlock
Grid.Row
=
"3"
Grid.Column
=
"0"
Text
=
"Max"
/>
<
telerik_pres:RadNumericUpDown
x:Name
=
"RnudDecimalMax"
Value
=
"{Binding Path=Max, Mode=TwoWay}"
Grid.Row
=
"3"
Grid.Column
=
"1"
NumberDecimalDigits
=
"0"
/>
</
Grid
>
</
StackPanel
>
<
StackPanel
Grid.Row
=
"2"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
</
Grid.ColumnDefinitions
>
<
Button
Content
=
"Test"
Click
=
"Button_Click"
Grid.Row
=
"0"
Grid.Column
=
"0"
/>
<
TextBlock
Text
=
"Entity value"
Grid.Row
=
"0"
Grid.Column
=
"1"
/>
<
TextBox
x:Name
=
"TxbResult"
Text
=
"empty"
Grid.Row
=
"0"
Grid.Column
=
"1"
/>
</
Grid
>
</
StackPanel
>
</
Grid
>
</
UserControl
>
Code behind:
using
System.Windows;
using
System.Windows.Controls;
namespace
SilverlightApplication
{
public
partial
class
MainPage : UserControl
{
Entity _entity;
public
MainPage()
{
InitializeComponent();
this
.DataContext = _entity =
new
Entity();
}
private
void
Button_Click(
object
sender, RoutedEventArgs e)
{
TxbResult.Text = _entity.DefaultValue;
}
}
}
Entity.cs:
using
System.ComponentModel;
namespace
SilverlightApplication
{
public
class
Entity : INotifyPropertyChanged
{
public
event
PropertyChangedEventHandler PropertyChanged;
private
string
_defaultValue;
public
int
Precision {
get
;
set
; }
public
int
Scale {
get
;
set
; }
public
int
Min {
get
;
set
; }
public
int
Max {
get
;
set
; }
public
virtual
string
DefaultValue
{
get
{
return
_defaultValue; }
set
{
_defaultValue = value;
InvokePropertyChanged(
"DefaultValue"
);
}
}
public
void
InvokePropertyChanged(
string
changedPropertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if
(handler !=
null
)
handler(
this
,
new
PropertyChangedEventArgs(changedPropertyName));
}
}
}
I'm trying to bind control DpDecimal to DefaultValue of an entity. I have also some properties of the default value like precision, scale,..
The control DpDecimal has bound its properties NumberDecimalDigits, Minimum, Maximum to controls of these properties. I have also one help button here and when click to this button the actual value of entity default value is filled into the textbox next to it, just for testing.
I'm trying this scenario:
1. fill min = 1, max = 1000, scale = 2, precision = 5 and default value = 500
2. change min value to 600 and click the button test before losing focus. This works and default value is changed in control and also in entity property to min value = 600.
3. change default value to 600,19
I need somehow to fix this to have changed also the value of the property in the entity. I also need to keep default value as a string because of the structure of my application. I did try to handle events from property controls and update the control of default value source explicitly but it also doesn't work. Neither change of UpdateEvent to PropertyChanged help.
Thanks for any advice.