2013-10-07 214 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