System.Windows.Controls.Buttonから継承された2つのカスタムコントロールが作成されました。 1つはXLButton
、もう1つはXLBox
です。 XLButtonがXLBox
ファイル内に表示されるXLButton
ファイルには「XLButton」が表示され、その逆はの場合と同じですが、2つの別々の.xamlファイルと同じコードビハインドファイルの2つの別々のResourceDictionary
オブジェクトに同じXAMLスタイル/。XAML ResourceDictionariesをGeneric.xamlに移動するとエラーが発生する
2行Grid
という簡単なテストウィンドウを作成しました。 ResourceDictionary
ファイルをそのテストウィンドウのWindow.Resources
にマージし、各カスタムコントロールのインスタンスを作成します.1つは最上部の行に、もう1つは下部にあります。これは正常に動作します。テストウィンドウのXAMLは次のとおりです。
<Window x:Class="ScratchPadWindow"
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:ExLuminaControls"
mc:Ignorable="d"
Title="ScratchPadWindow" Height="118" Width="145">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Styles/XLBox.xaml" />
<ResourceDictionary Source="/Styles/XLButton.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<local:XLBox Content="Hi!"/>
<local:XLButton Grid.Row="1" Content="Yeah!"/>
</Grid>
</Window>
これはうまくいきます。それは次のようになりますので、私は、ResourceDictionary.MergedDictionaries
セクションをコメントアウトしてThemes\Generic.xaml
に元の形でそれをコピーする場合でも、:
<ResourceDictionary
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:ExLuminaControls"
mc:Ignorable="d">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Styles/XLButton.xaml" />
<ResourceDictionary Source="/Styles/XLBox.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
私はに関連した「リソースを見つけることができません 『スタイル/ xlbutton.xaml』というエラーを取得しますこのライン:
<local:XLBox Content="Hi!"/>
私には意味をなさないが、何より混乱だが、私はデザイナーで「無効プロジェクトコード」をクリックすると、問題が消えるということではありません
私は。ブレンド2を使用して017コミュニティ。
誰でも分かりますか?
ありがとうございます!
私は違いがないことを恐れています。これは 'ResourceDictionary'参照を' Window'の.xamlファイルに置いても動作しますが、パスの '/ ExLuminaControls; Component'部分があってもなくてもかまいません。 xaml'ファイル。 –
確認するには、他に3つ、上記を参照 – GCamel
ありがとうございます。 BlendからVSに移ったときにあなたのパスがrefを修正しました。他のすべてのものはうまくチェックします。問題は、明らかに私が思ったより微妙なことです。カスタムスタイルはgeneric.xamlで定義されても効果がありません。スタイル定義をgeneric.xamlファイルに直接移動すると、それでも効果はありません。しかし、名前を除いて最初のプロジェクトと同じ2番目のプロジェクトを作成すると、2番目のプロジェクトは最初のプロジェクトからカスタムコントロールをインスタンス化でき、generic.xamlのスタイルが適用されます。 generic.xamlがそれ自身のプロジェクトになぜ適用されないのか分かりません。あなたの答えを正しいものにしてください。 –