0
初心者でWPFを使用しています。私はcss/sassのようにしたい。私はいくつかの定義を再利用したい。WPF ResourceDictionary and Binding
ここでは、要素(ボタンなど)で色の定義を再利用したいとします。私は「staticresource」との結合を使用している場合は実行しているとき、私は次の例外を取得:
「型 『System.Windows.Markup.XamlParseException』の未処理の例外がPresentationFramework.dll で発生しました追加情報: 『#1 FF8FA2AC』 IST KEINのgültigerワートのfürEigenschaft "背景" 死ぬ。私は他の要素で定義済みの定義を使用するにはどうすればよい「
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Color x:Key="cyan3">#007ca9</Color>
<Color x:Key="mangenta2">#a8005c</Color>
<Color x:Key="wintergrey1">#e6ecf0</Color>
<Color x:Key="wintergrey2">#c3ced5</Color>
<Color x:Key="wintergrey3">#8fa2ac</Color>
<Color x:Key="wintergrey4">#506671</Color>
<Color x:Key="white">#FFFFFF</Color>
<Color x:Key="antrazit">#333333</Color>
<!-- Base style for button -->
<Style TargetType="Button" x:Key="btnStandard">
<!--Setter Property="Background" Value="#8fa2ac"/-->
<Setter Property="Background" Value="{StaticResource wintergrey3}"/>
<Setter Property="Foreground" Value="#ffffff"/>
<Setter Property="Width" Value="150" />
<Setter Property="Height" Value="30"/>
</Style>
</ResourceDictionary>
?または何が間違っている。
'Background'は色ではなく、' Brush'です。リソース(例えばSolidColorBrush)内のブラシを宣言して、あなたの中でそれらを再利用してください。スタイルとビュー; btw、 '"#8fa2ac "16進コードからブラシを作成 –
ASh
[XAMLでカラーをブラシに変換する方法は? (http://stackoverflow.com/questions/3309709/how-do-i- xamlで変換するa-color-to-a-xaml) – MikeT