Thursday, January 29, 2015

Set style for Control in UserControl

I have a issue with set style for Control in UserControl.


1 - I create a UserControl wrapper PasswordBox(need to override some method for PasswordBox) :



<UserControl
x:Class="Test.WrapperPasswordBox"
xmlns="http://ift.tt/w9rHWX;
xmlns:x="http://ift.tt/zZkFEV;
xmlns:local="using:Test"
xmlns:d="http://ift.tt/PuXO1J;
xmlns:mc="http://ift.tt/R4RR6u;
mc:Ignorable="d">

<Grid>
<PasswordBox x:Name="PasswordBox" />
</Grid>
</UserControl>



2 - I create a Style in App.xaml:



<Style TargetType="PasswordBox"
x:Key="GlobalPasswordBox">
<Setter Property="FontSize"
Value="30" />
<Setter Property="Height"
Value="50" />
</Style>



3 - I replace PasswordBox with WrapperPasswordBox in MainPage.xaml :



<PasswordBox Style="{StaticResource GlobalPasswordBox}">

==>

<WrapperPasswordBox Style="{StaticResource GlobalPasswordBox}">



My issue is : When i run to MainPage.xaml, application will crash.


I know : can't set style of PasswordBox for UserControl. But i can't move Style in MainPage.xaml to PasswordBox of UserControl because i have another style for PasswordBox in another Page.




Do you have any suggestion for this issue ?


No comments:

Post a Comment