我有下一个UserControl:
<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=""/>
</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];
并且无法弄清楚如何输入设定此值?
这怎么可能是这样的:
答案 0 :(得分:0)
安装人员已密封。即使您将它们作为Setter转换为可以访问属性Value代替SetterBase,当您尝试修改它们时,您将获得运行时异常。
我认为您可以找到一个解决方案,在本主题中执行您想要的操作: Change a style dynamically in WPF