2013-10-07 180 views
0

我旁边用户控件:访问setter属性

<UserControl 
x:Class="Test.Views.NavigationMenu" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:RTUforWindows8.Views" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
d:DesignHeight="300" 
d:DesignWidth="400"> 
<UserControl.Resources> 
    <Style x:Key="HomeAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource AppBarButtonStyle}"> 
     <Setter Property="AutomationProperties.AutomationId" Value="HomeAppBarButton"/> 
     <Setter Property="AutomationProperties.Name" Value="ewffgwefwfwefwefwe"/> 
     <Setter Property="Content" Value="&#xE10F;"/> 
    </Style> 
</UserControl.Resources> 

<StackPanel Orientation="Horizontal"> 
    <Button 
     Style="{StaticResource HomeAppBarButtonStyle}" /> 
    <Button 
     Style="{StaticResource AppBarButtonStyle}" /> 
</StackPanel> 

而且在我的代码我想改变:

<Setter Property="AutomationProperties.Name" Value="ewffgwefwfwefwefwe"/> 

价值的东西,我做的:

NavigationMenu NM = new NavigationMenu(); 
     var style = (NM.Resources["HomeAppBarButtonStyle"] as Style).Setters[1]; 

而不能弄清楚如何输入set th是价值吗?

这怎么可能应该是这样的:

enter image description here

回答

0

的制定者是密封的。即使您将它们转换为Setter以访问属性Value而不是SetterBase,您将在尝试修改它们时收到运行时异常。

我认为你可以找到一个解决方案,做你想要什么本主题: Change a style dynamically in WPF