i want slider
value to binding on textbox
and textbox
to slider
value(user interaction).
im now just textbox
binded of slider
value. How can i get it?
<TextBox
Width="70"
Height="20"
Grid.Row="1"
Margin="0 0 80 180"
x:Name="AO1text"
Text="{Binding ElementName=AOch1,Path=Value, StringFormat={}{0:F2}}"/>
<Slider
x:Name="AOch1"
Maximum="20"
Minimum="4"
Value="{Binding ao1value}"
Width="250"
BorderThickness="5"
TickPlacement="BottomRight"
try this
<TextBox Width="120" Text="{Binding ElementName=AOch1, Path=Value, StringFormat={}{0:N0}, UpdateSourceTrigger=PropertyChanged}"/>
<Slider x:Name="AOch1" Maximum="100" Minimum="0" Width="250" />
// Get value from Slider
targetObject.Value = AOch1.Value;
The recommended approach is:
public class ItemModel
{
double _Value = 4;
public double Value
{
get => _Value;
set
{
if (value < 4)
value = 4;
if (value > 20)
value = 20;
if (_Value != value)
{
_Value = value;
// Notify Property Changed
}
}
}
}
// Window1.xaml.cs
ItemModel model = new ItemModel();
// Window1_Loaded
yourGrid.DataContext = model;
<TextBox Text="{Binding Path=Value, StringFormat={}{0:F2}, UpdateSourceTrigger=PropertyChanged}"/>
<Slider Value="{Binding Path=Value}" Maximum="20" Minimum="4" Width="250" BorderThickness="5" TickPlacement="BottomRight" />