저는 WPF 형식이 처음이므로 TreeViewItem에서 배경을 설정하려고 할 때 문제가 발생했습니다.TreeViewItem의 배경색이 전체 너비가 아닙니다.
<Window x:Class="wpf_test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<!--Styles-->
<Style x:Key="GUIEntity" TargetType="{x:Type Control}">
<Setter Property="MinWidth" Value="150" />
<Setter Property="MaxWidth" Value="150" />
</Style>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="True" />
</Style>
<!--Data Sources-->
<x:Array x:Key="BooleanListData" Type="sys:String" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:String>True</sys:String>
<sys:String>False</sys:String>
</x:Array>
</Window.Resources>
<Grid>
<TreeView Name="treeView1" Margin="5" Background="Azure">
<TreeViewItem Header="ComplexTypeProperty" Margin="5">
<CheckBox Style="{StaticResource GUIEntity}" Margin="3,3,10,3" Content="Instance" />
<StackPanel Orientation="Horizontal" Background="LightGray">
<Label Margin="0,2,0,0" Content="IsBoolProperty" Width="150" />
<ComboBox Margin="5" Style="{StaticResource GUIEntity}" ItemsSource="{StaticResource BooleanListData}" />
</StackPanel>
</TreeViewItem>
</TreeView>
</Grid>
</Window>
StackPanel에서 설정되는 배경이 TreeView 컨트롤의 전체 너비 (오른쪽)로 이동하지 않는 것이 문제입니다. TreeView에서 모든 컨트롤에 HorizontalAllignment="Stretch"
을 추가하려고 시도했지만 효과가 없습니다. StackPanel의 배경 폭은 ComboBox의 끝까지 만 이동합니다.
TreeView에 배경을 설정하면 문제의 원인이되지 않도록 양식의 전체 너비를 차지한다는 것을 확인했습니다.
누구든지 TreeView 크기의 끝에 배경을 확장하는 방법을 알고 있습니까?
어떻게 가장 간단한 방법이 그리드를 무시 가겠어요?
이 질문을 커버하는 유일한 적절한 해결책을이다 : http://stackoverflow.com/questions/15826637/wpf-treeview-item-background-over- 전체 행 '코드' <스타일 BasedOn = "{정적 리소스 {X : 유형 TreeViewItem}}"은 TargetType = "TreeViewItem"> TreeView.ItemContainerStyle> –
@GeorgySmirnov는 머리글에 배경을 설정하기 만합니다. 그것은 다른 것에 영향을 미치지 않습니다. 그리고 헤더의 배경은 전체 너비가 아닌 텍스트까지만 확장됩니다. (또한 너비가 왼쪽으로 확장되는 것을 원하지 않았고 오른쪽 만). –
내가 본 것을 보면 강조 표시된 격자에'Grid.ColumnSpan = "2"'을하고 싶을 것입니다. 그렇게하면 원하는 것을 할 수 있습니다. 그러나 나는 그것을 어떻게합니까? –