0
votes

I read some tutorials on building user controls in wpf before embarking on building my own. Many of these centred around creating a control based on a standard button with the facility to add an imge and custom text. Most of these also seemed to actively define the image dimensions and bind them to a dependency property so you might end up with xaml like this;

 <Button Background="#00000000" x:Name="MyBtn" Height="Auto" Width="Auto" ToolTip="Click me to do something." BorderThickness="0">
        <StackPanel Margin="2" Orientation="Horizontal">
            <Image Source="{Binding ImageName, ElementName=DN}"
                   Width="{Binding ImageWidth, ElementName=DN}"
                   Height="{Binding ImageHeight, ElementName=DN}"/>
            <TextBlock Margin="3" Text="{Binding BtnText,ElementName=DN}"/>
        </StackPanel>
        </Button>

Is it actually necessary to specifically define the Image Width and Height?

Thanks

1

1 Answers

1
votes

You don't need to but if you don't the image will just take its own height and width (or the whole available space, if it's inferior), which could be 1920x1080 and take the whole space.

Edit on containers

Most container will stretch it and make the image fill the whole space (according to the tiniest orientation). Some, like your StackPanel will only according to its Orientation property. A Canvas won't resize anything and the image will take its own size.