ボタン内の画像とテキストをサポートするために、次のような単純なユーザーコントロールを作成しました。
<UserControl x:Class="wpf_Templates.UC.rb"
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"
DataContext="{Binding RelativeSource={RelativeSource Self}}" >
<Grid>
<Button Name="rbutton1">
<StackPanel Orientation="{Binding Layout}" Background="Beige">
<Image Source="{Binding Image}" />
<TextBlock Text="{Binding Text}" Margin="3,3,0,0" HorizontalAlignment="Center"/>
</StackPanel>
</Button>
</Grid>
Text 、 Image の 2 つの DependencyProperty があります。
MainWindow.xaml で、このようにインスタンス化します
<lcl:rb Text="Rb" Image="Resources\Images\Exit.gif" MinWidth="40"></lcl:rb>
アプリケーションを実行すると、テキストと画像のボタンが表示されますが、デザイン モードでは空のフレームが表示されます。なぜ ?
ありがとう、アヴィ。