0

ボタン内の画像とテキストをサポートするために、次のような単純なユーザーコントロールを作成しました。

<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>

アプリケーションを実行すると、テキストと画像のボタンが表示されますが、デザイン モードでは空のフレームが表示されます。なぜ ?

ありがとう、アヴィ。

4

2 に答える 2

0

MainWindow.xaml の Window 宣言に次の属性を追加できます。

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" 

そして、あなたのコントロールの宣言で:

<lcl:rb Text="Rb" 
        Image="Resources\Images\Exit.gif" 
        d:Image="Resources\Images\Exit.gif"  
        MinWidth="40">
</lcl:rb>

このようにして、デザイナーは何を使うべきかを知っています。

于 2012-11-19T08:05:51.087 に答える