1
カスタムToggleButtonテンプレートに(Dependency Propertyを介して)カスタムプロパティを追加したいとします。 今、私は、 "Hello"と実際のプロパティ値の連結値になるように、(将来の実装のためのプレースホルダとして)ラベルを含む値を持っていたいと思います。それは(ラベルの「戦士」を表示)正常に動作連結なしWPF TemplateBinding値の文字列を連結する
しかし、私は、XAMLのdoesntのはもうコンパイル連結としてラベルを設定しようとします。
<Label Content="Hello {TemplateBinding local:HeroClassCheckbox.HeroClass}"/>
これをどのように達成できますか?
残りのコード:
私の.xaml
<Window.Resources>
<ResourceDictionary>
<Style x:Key="HeroClassCheckbox" TargetType="ToggleButton">
<Setter Property="Content" Value="Green" />
<Setter Property="local:HeroClassCheckbox.HeroClass" Value="NoClass"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Label Content="{TemplateBinding local:HeroClassCheckbox.HeroClass}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</Window.Resources>
<Grid>
<ToggleButton Width="150" Height="50" local:HeroClassCheckbox.HeroClass="Warrior" Style="{DynamicResource HeroClassCheckbox}"/>
</Grid>
マイ.xaml.cs
public static class HeroClassCheckbox
{
public static readonly DependencyProperty HeroClassProperty = DependencyProperty.RegisterAttached("HeroClass",
typeof(string), typeof(HeroClassCheckbox), new FrameworkPropertyMetadata(null));
public static string GetHeroClass(UIElement element)
{
if (element == null)
throw new ArgumentNullException("element");
return (string)element.GetValue(HeroClassProperty);
}
public static void SetHeroClass(UIElement element, string value)
{
if (element == null)
throw new ArgumentNullException("element");
element.SetValue(HeroClassProperty, value);
}
}
: 「名前 『HelloLabelConverterは、CLR名前空間』名前空間に存在しません 『:WpfApplication1』 \t WpfApplication1 " 明らかに存在するので奇妙です。私はここで間違って何をしていますか? [.xaml](http://pastebin.com/Fm7esb4S) [.xaml.cs](http://pastebin.com/Q8urWFQJ) –
私たちが見えないときは、その問題を理解するのは難しいですあなたのプロジェクトファイルの構造。価値コンバーターを使用する方法についてのチュートリアルを探し、それが役に立つかどうかを確認してください –
これは単なる標準プロジェクト(新しいプロジェクト - > wpfプロジェクト)ですが、私はバリューコンバーターに関するチュートリアルを探します。 –