C# 访问Setter属性
我有下一个用户控件:C# 访问Setter属性,c#,wpf,xaml,C#,Wpf,Xaml,我有下一个用户控件: <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.m
<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以访问属性值而不是SetterBase,当您尝试修改它们时,也会出现运行时异常 我认为您可以在本主题中找到一个解决方案:
<Setter Property="AutomationProperties.Name" Value="ewffgwefwfwefwefwe"/>
NavigationMenu NM = new NavigationMenu();
var style = (NM.Resources["HomeAppBarButtonStyle"] as Style).Setters[1];