我对wpf比较陌生。
目前,我正在编写Textadventure,玩家可以在其中做出决定。为了检测选择了哪个选项,我想添加一个自定义附加属性来存储信息。我的问题是,我正在接收错误,我的自定义属性在我的命名空间中不存在。我的问题是,我的代码中缺少什么才能使其正常工作。对于这种情况,我也愿意提供其他解决方案。
以下是我在c#中的代码:
namespace A_Fairytale
{
public static class CustomProperties
{
public static readonly DependencyProperty HiddenInfo = DependencyProperty.RegisterAttached(
"HiddenInfo",
typeof(string),
typeof(Control),
new FrameworkPropertyMetadata("")
);
public static string GetHiddenInfo(UIElement element)
{
if (element == null)
throw new ArgumentNullException("HiddenInfo");
return (string)element.GetValue(HiddenInfo);
}
public static void SetHiddenInfo(UIElement element, string value)
{
if (element == null)
throw new ArgumentNullException("HiddenInfo");
element.SetValue(HiddenInfo, value);
}
}
}
和XAML:
<Window x:Class="A_Fairytale.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:A_Fairytale"
mc:Ignorable="d"
WindowState="Maximized"
WindowStyle="None"
Title="MainWindow" Height="600" Width="1500">
<Grid Name="ContentWrapper">
<DockPanel Name="ChoiceContainer" Grid.Row="1" Grid.Column="1">
<Button local:CustomProperties.HiddenInfo="" DockPanel.Dock="Left" Name="choice_left" Click="Choice_Click" FontWeight="Bold" FontSize="15" Style="{StaticResource ButtonWithCustomHover}"></Button>
<Button local:CustomProperties.HiddenInfo="" DockPanel.Dock="Right" Name="choice_right" Click="Choice_Click" FontWeight="Bold" FontSize="15" Style="{StaticResource ButtonWithCustomHover}"></Button>
<Button local:CustomProperties.HiddenInfo="" Name="choice_center" Click="Choice_Click" FontWeight="Bold" FontSize="15" Style="{StaticResource ButtonWithCustomHover}"></Button>
</DockPanel>
<Button Name="Continue" Grid.Row="2" Grid.Column="1" Visibility="Collapsed" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" FontWeight="Bold" FontStyle="Italic" FontSize="40">Weiter</Button>
</Grid>
</Window>