使用Silverlight 3我试图重新创建类对象可视化,如Visual Studio的类图中所示。但是,我的对象将表示数据库对象而不是类定义。我在以下两张图片中看到了部分成功。
alt text http://img41.imageshack.us/img41/5669/tablestructurenotexpandb.png a http://img41.imageshack.us/img41/7634/tablestructurenotexpand.png
这两个都是使用固定大小创建的,因此它们不会自动调整内容,这是正确的。
但是,我希望能够分别根据控件中的行数和列数自动调整控件的高度和宽度。我希望能够完全以声明的方式做到这一点。另外,即使我更改字体,我也希望它能正确自动调整。
然而,我不确定如何做到这一点。我不确定我是否使用或多或少适合自动调整大小的控件。任何帮助将非常感激。
以下是创建此控件的XAML。
<UserControl x:Class="SchemaDesigner.TableBox2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Border BorderThickness="1" BorderBrush="#FF716F6E" CornerRadius="10" Width="252" Height="202"> <!-- Height="202"-->
<Canvas>
<Canvas.Clip>
<RectangleGeometry RadiusX="10" RadiusY="10" Rect="0,0,250,200"/>
</Canvas.Clip>
<StackPanel Width="250" Background="White">
<StackPanel Width="250" Height="45" Orientation="Vertical">
<StackPanel.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="#FFD3DCEF" Offset="0.0" />
<GradientStop Color="#FFFFFFFF" Offset=" 1.0"/>
</LinearGradientBrush>
</StackPanel.Background>
<StackPanel Width="250" Orientation="Horizontal">
<StackPanel Width="210" Height="45" Orientation="Vertical">
<TextBlock Text="{Binding Name}" Width="190" HorizontalAlignment="Left" FontFamily="Verdana" Margin="10,10,0,0" VerticalAlignment="Top" FontWeight="Black" FontSize="12"/>
<TextBlock Text="{Binding Type}" Width="190" HorizontalAlignment="Left" FontFamily="Verdana" Margin="10,0,0,0" VerticalAlignment="Top" FontStyle="Italic"/>
</StackPanel>
<Button Width="20" Height="20" VerticalAlignment="Top" Margin="10" Content="^" FontFamily="Verdana" />
</StackPanel>
</StackPanel>
<ItemsControl x:Name="items" ItemsSource="{Binding Rows}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Width="250" Orientation="Horizontal">
<Image Width="16" Height="16" VerticalAlignment="Center" Source="/SchemaDesigner;component/column.png"/>
<TextBlock Text="{Binding ColumnName}" Width="100" Height="20"/>
<TextBlock Text="{Binding ColumnType}" Width="130" Height="20"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Canvas>
</Border>
</UserControl>
答案 0 :(得分:1)
我已经完成了代码,并且有很多地方明确设置了高度,这会干扰布局计算。
所做的更改如下:
使用正确的属性/子集合创建一个虚拟本地类并绑定到它,结果看起来像我认为你想要的。如果您希望蓝色背景的底部也是曲线,则堆叠面板剪辑的高度应设置为45。
别忘了重新命名课程,我的版本只是mainpage1。
希望有所帮助
一个。
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Border BorderThickness="1" BorderBrush="#FF716F6E" CornerRadius="10" VerticalAlignment="Center" HorizontalAlignment="Center">
<StackPanel Width="250" Orientation="Vertical" VerticalAlignment="Center">
<StackPanel Width="250" Height="45" Orientation="Vertical" >
<StackPanel.Clip>
<RectangleGeometry RadiusX="10" RadiusY="10" Rect="0,0,250,55"/>
</StackPanel.Clip>
<StackPanel.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="#FFD3DCEF" Offset="0.0" />
<GradientStop Color="#FFFFFFFF" Offset=" 1.0"/>
</LinearGradientBrush>
</StackPanel.Background>
<StackPanel Width="250" Orientation="Horizontal">
<StackPanel Width="210" Height="45" Orientation="Vertical">
<TextBlock Text="{Binding Name}" Width="190" HorizontalAlignment="Left" FontFamily="Verdana" Margin="10,10,0,0" VerticalAlignment="Top" FontWeight="Black" FontSize="12"/>
<TextBlock Text="{Binding Type}" Width="190" HorizontalAlignment="Left" FontFamily="Verdana" Margin="10,0,0,0" VerticalAlignment="Top" FontStyle="Italic"/>
</StackPanel>
<Button Width="20" Height="20" VerticalAlignment="Top" Margin="10" Content="^" FontFamily="Verdana" />
</StackPanel>
</StackPanel>
<ItemsControl x:Name="items" ItemsSource="{Binding Rows}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Width="250" Orientation="Horizontal">
<Image Width="16" Height="16" VerticalAlignment="Center" Source="/SchemaDesigner;component/column.png"/>
<TextBlock Text="{Binding ColumnName}" Width="100" />
<TextBlock Text="{Binding ColumnType}" Width="130" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Border>
</UserControl>