WPF
[ wpf ] Property Grid 만드는 법
code094
2022. 11. 24. 17:03
xaml
- 한 속성에 가로로 3개의 라디오 버튼을 넣음
<DataTemplate x:Key="NumberEditor" >
<Grid>
<StackPanel >
<StackPanel.Resources>
<Style x:Key="Flag" TargetType="RadioButton" BasedOn="{StaticResource {x:Type ToggleButton}}">
</Style>
</StackPanel.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ItemsControl >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<RadioButton x:Name="One" Grid.Column="0" Style="{StaticResource Flag}" BorderBrush="White" Height="21" GroupName="gender" >
<RadioButton.Content>
<TextBlock Text="one" TextWrapping="Wrap" Foreground="White"/>
</RadioButton.Content>
</RadioButton>
<RadioButton x:Name="Two" Grid.Column="1" Style="{StaticResource Flag}" BorderBrush="White" Height="21" GroupName="gender">
<RadioButton.Content>
<TextBlock Text="two" TextWrapping="Wrap" Foreground="White"/>
</RadioButton.Content>
</RadioButton>
<RadioButton x:Name="All" Grid.Column="2" Style="{StaticResource Flag}" BorderBrush="White" Height="21" IsChecked="True" GroupName="gender">
<RadioButton.Content>
<TextBlock Text="all" TextWrapping="Wrap" Foreground="White"/>
</RadioButton.Content>
</RadioButton>
</Grid>
</StackPanel>
</Grid>
</DataTemplate>
2. 속성을 보여줄 곳 . 여기는 탭에 속성 넣어줌
<TabItem Header="속성" Width="80">
<sfw:PropertyGrid Name="SearchPropertyGrid" BorderThickness="1" BorderBrush="#464646"
xmlns:sfw="clr-namespace:SoftFluent.Windows;assembly=SoftFluent.Windows" />
</TabItem>
c#
1. 씨샵 클래스 하나 만들어서 property 입력함
#region 1.Number
```
[Category("number")]
[DisplayName("number")]
[PropertyGridOptions(EditorDataTemplateResourceKey = "NumberEditor", SortOrder = 100)]
public sbyte Num
{
get { return GetProperty<sbyte>(0, "Num"); }
set { SetProperty(value); }
}
#endregion
```