0
如何在後面的代碼中創建類似這樣的內容?在代碼隱藏中創建自定義數據綁定工具提示
<Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="HasDropShadow" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<Border CornerRadius="5" HorizontalAlignment="Center" VerticalAlignment="Top" Padding="1" BorderThickness="1,1,1,1">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#F7D073" Offset="0"/>
<GradientStop Color="#F1A62F" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border HorizontalAlignment="Stretch" BorderThickness="0,0,0,1" BorderBrush="Black" Margin="5" Grid.ColumnSpan="2">
<TextBlock FontSize="14" TextAlignment="Left" Text="{TemplateBinding Content}"/>
</Border>
<TextBlock Grid.Column="0" Grid.Row="1" Margin="10,0,5,0">Column1:</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="1" FontWeight="Bold" Text="{Binding Column1}" TextAlignment="Left" />
<TextBlock Grid.Column="0" Grid.Row="2" Margin="10,0,5,0">Column2:</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="2" FontWeight="Bold" Text="{Binding Column2}" TextAlignment="Left" />
<TextBlock Grid.Column="0" Grid.Row="3" Margin="10,0,5,0">Column3:</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="3" FontWeight="Bold" Text="{Binding Column3}" TextAlignment="Left" />
<TextBlock Grid.Column="0" Grid.Row="4" Margin="10,0,5,0">Column4:</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="4" FontWeight="Bold" Text="{Binding Column4}" TextAlignment="Left" />
<TextBlock Grid.Column="0" Grid.Row="5" Margin="10,0,5,0">Column5:</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="5" FontWeight="Bold" Text="{Binding Column5}" TextAlignment="Left" />
<TextBlock Grid.Column="0" Grid.Row="6" Margin="10,0,5,0">ColumnX:</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="6" FontWeight="Bold" Text="{Binding ColumnX}" TextAlignment="Left" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
的想法是在一個DataTable傳遞給控制與未知的列數,並能夠建立與然而,許多列有一個提示。
上面的代碼被用來構建一個非常具體的案例,但現在我想盡可能通用,但是我對WPF代碼隱藏的瞭解並不是它需要創建類似這樣的東西的地方。
你爲什麼要在代碼隱藏中創建類似的東西?您應該使用在XAML中設計的ListView或GridView,並將它們綁定到您的DataTable - 全部在XAML中。請看看他們。 – Alain 2012-04-11 15:23:14
感謝Alain對此的建設性意見。然而,這個想法是,這個工具提示可以用於說組合框顯示column1和鼠標懸停的組合框,tooltip顯示並顯示所有其他列。 – TriStar 2012-04-11 15:36:39