Hi all,
I'm Trying to get the value of a slider thats contained in a window from a usercontrol thats also contained in that window.
this is what i would like to accomplish.
<Window x:Class="TestApp3.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1">
<Window.Resources>
<Style x:Key="SliderStyle" TargetType="{x:Type Slider}">
<Setter Property="Value" Value="10" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Interval" Value="1" />
<Setter Property="Minimum" Value="5" />
<Setter Property="Maximum" Value="50" />
<Setter Property="TickFrequency" Value="0.25" />
<Setter Property="IsSnapToTickEnabled" Value="True" />
<Setter Property="Width" Value="100" />
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="FontSize" Value="{Binding ElementName=SliderFont, Path=Value}" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="Test" />
<Border
Grid.Row="1"
Background="Purple"
BorderBrush="Black"
BorderThickness="1"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
FontSize="16"
Content="Font Size:"/>
<TextBox
Grid.Column="1"
FontSize="16"
Text="{Binding ElementName=SliderFont, Path=Value, Mode=TwoWay}"
Width="50"
MaxLength="5" />
<Slider
Style="{DynamicResource SliderStyle}"
Grid.Column="2"
Name="SliderFont" />
</Grid>
</Border>
</Grid>
</Window>
same idea but using a usercontrol.
<Window x:Class="TestApp3.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestApp3"
Title="Window1">
<Window.Resources>
<Style x:Key="SliderStyle" TargetType="{x:Type Slider}">
<Setter Property="Value" Value="10" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Interval" Value="1" />
<Setter Property="Minimum" Value="5" />
<Setter Property="Maximum" Value="50" />
<Setter Property="TickFrequency" Value="0.25" />
<Setter Property="IsSnapToTickEnabled" Value="True" />
<Setter Property="Width" Value="100" />
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="FontSize" Value="{Binding ElementName=SliderFont, Path=Value}" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<!--<TextBox Grid.Row="0" Text="Test" />-->
<local:myusercontrol Grid.Row="0" />
<Border
Grid.Row="1"
Background="Purple"
BorderBrush="Black"
BorderThickness="1"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
FontSize="16"
Content="Font Size:"/>
<TextBox
Grid.Column="1"
FontSize="16"
Text="{Binding ElementName=SliderFont, Path=Value, Mode=TwoWay}"
Width="50"
MaxLength="5" />
<Slider
Style="{DynamicResource SliderStyle}"
Grid.Column="2"
Name="SliderFont" />
</Grid>
</Border>
</Grid>
</Window>
The usercontrol
<UserControl x:Class="TestApp3.myusercontrol"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<TextBox Text="Test" />
</Grid>
</UserControl>
The usercontrols textbox fontsize isnt growing at all. the reason i want to get this working is cause i'd like to put somthing like it in our themes so we wont have to worry about it later on. I've been tinkering with this for far too long. Any ideas on how to get this working would be great.
i know i can pass along the FontSize value in the usercontrol but i'd like to be able to control more than one controls FontSize.
Hope this makes sense, ~Boots