Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 访问Setter属性_C#_Wpf_Xaml - Fatal编程技术网

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="&#xE10F;"/>
    </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];