私はUserControlを作成し、ResourcesDictionaryを書きました。いくつかのスタイルがあります。userControlのResourceDictionaryをapp.xamlにマージできますか?
そして、私はResourceDictionaryをApp.xamlにマージしたいと思います。
しかし、メインプロジェクトはAで、App.xamlがあります。
UserControlはBプロジェクトに入っているので、別の場所に住んでいます。
どのようにResourceDictonaryをマージできますか?
ここは私のコードの一部ですが、動作しません。 App.xamlで
まず試しは
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="myUserControl.xaml"/>
</ResourceDictionary.MergedDictionaries> ......
セカンド
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/B;component/SubFolderName/myUserControl.xaml" />
</ResourceDictionary.MergedDictionaries> ......
第三には、
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/B;component/SubFolderName/myUserControl.xaml" />
</ResourceDictionary.MergedDictionaries> ......
彼らはすべてを試してみ動作しませんでした.....
+ myUserControl.xaml
<UserControl x:Class="........."
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:B"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="100">
<UserControl.Resources>
<ResourceDictionary>
<Style x:Key="TitleTest" TargetType="TextBlock" BasedOn="{StaticResource MetroTextBlock}">
<Setter Property="Margin" Value="15"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="FontSize" Value="20"/>
</Style>
<Style x:Key="PanelTestStyle" TargetType="StackPanel">
<Setter Property="ClipToBounds" Value="True"/>
<Setter Property="Height" Value="55"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Margin" Value="15"/>
</Style>
<Style x:Key="TestStyle2" TargetType="TextBlock" BasedOn="{StaticResource MetroTextBlock}">
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="FontSize" Value="40"/>
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<TextBlock Text="{Binding StatusTitle}" Style="{DynamicResource TitleTest}"/>
<StackPanel Style="{StaticResource PanelTestStyle}">
<TextBlock x:Name="testText" Style="{DynamicResource TestStyle2}" Text="{Binding StatusNumber}"/>
<TextBlock x:Name="testText2" Style="{DynamicResource TestStyle2}" Text="TEST" />
</StackPanel>
</Grid>
また、私はセッターの値がCSコード内のFontSizeを変更するには取得したいので、私がする必要がありますDynamicResource(TextBlocks)を設定します。
myUserControl.xamlのxamlを投稿できますか? –
コントロールを辞書にマージすることはできません.Xamlをユーザーコントロールからアプリケーションのリソースセクションに移動するか、スタンドアロンリソースディクショナリで作成します。 – MikeT
@MikeTはい、そのためにxamlコードを確かに彼は本当にUserControlとマージしようとします。 –