在“数据源”窗口中为属性指定自定义控件时,将该对象拖放到“窗口”上会创建一个大小为100 * 100的控件。 (控件中没有硬编码大小。)
尝试匹配Label的HorizontalContentAlignment和VerticalContentAlignment值,因为它们似乎是唯一不同但控制大小无差异100 * 100的值。 (除非我手动修复它)
向导生成的代码:
<Label Content="Url:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="2" VerticalAlignment="Center"/>
<HyperLinkControl x:Name="urlHyperLinkControl2" Grid.Column="1" HorizontalAlignment="Left" Height="100" Margin="3" Grid.Row="2" Uri="{Binding Url}" VerticalAlignment="Center" Width="100"/>
我的UserControl中是否还需要定义其他属性来覆盖默认大小?
向导生成的XAML:
<Grid x:Name="grid1" DataContext="{StaticResource biographyViewSource}" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Site:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
<TextBlock x:Name="siteTextBlock1" Grid.Column="1" HorizontalAlignment="Left" Margin="3" Grid.Row="0" Text="{Binding Site}" VerticalAlignment="Center"/>
<Label Content="Text:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="1" VerticalAlignment="Center"/>
<TextBlock x:Name="textTextBlock1" Grid.Column="1" HorizontalAlignment="Left" Margin="3" Grid.Row="1" Text="{Binding Text}" VerticalAlignment="Center"/>
<Label Content="Url:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="2" VerticalAlignment="Center"/>
<SharpControls:HyperLinkControl x:Name="urlHyperLinkControl2" Grid.Column="1" HorizontalAlignment="Left" Height="100" Margin="3" Grid.Row="2" Uri="{Binding Url}" VerticalAlignment="Center" Width="100"/>
<Label Content="Attribution:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="3" VerticalAlignment="Center"/>
<TextBlock x:Name="attributionTextBlock1" Grid.Column="1" HorizontalAlignment="Left" Margin="3" Grid.Row="3" Text="{Binding License.Attribution}" VerticalAlignment="Center"/>
<Label Content="Type:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="4" VerticalAlignment="Center"/>
<TextBlock x:Name="typeTextBlock1" Grid.Column="1" HorizontalAlignment="Left" Margin="3" Grid.Row="4" Text="{Binding License.Type}" VerticalAlignment="Center"/>
<Label Content="Url:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="5" VerticalAlignment="Center"/>
<SharpControls:HyperLinkControl x:Name="urlHyperLinkControl3" Grid.Column="1" HorizontalAlignment="Left" Height="100" Margin="3" Grid.Row="5" Uri="{Binding License.Url}" VerticalAlignment="Center" Width="100"/>
</Grid>
答案 0 :(得分:-1)
在SharpControls:HyperLinkControl
您已设置属性Height=100
。只需删除此属性即可。