2017-03-23 1 views
0

그래서 이것은 내 사용자 지정 GroupBox입니다 :는 WPF는 : 라벨 CornerRadius를이 국경에서

<Grid Width="550" Height="140" Margin="20,0,0,0"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="20"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 
    <Border BorderThickness="1,1,1,0" BorderBrush="Gray" CornerRadius="5,5,0,0" > 
     <Label 
      Height="25" 
      Width="60" 
      HorizontalAlignment="Left" 
      Background="#FF7AA0CD" 
      BorderBrush="Gray" 
      BorderThickness="1" 
      Foreground="Gainsboro" 
      Content=" Options" 
      Margin="10,-18,0,0"/> 
    </Border> 
    <Border Grid.Row="1" BorderThickness="1,0,1,1" BorderBrush="Gray" CornerRadius="0,0,5,5"> 
     <StackPanel Orientation="Vertical" Margin="0,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"> 
      <StackPanel Orientation="Horizontal" Margin="10,0,0,0" > 
       <Label 
     Content="Interface: " 
     Margin="0,3,0,0"/> 
       <ComboBox 
      MaxDropDownHeight="110" 
      Style="{DynamicResource ComboBoxFlatStyle}" 
      ItemsSource="{Binding interfaces}" 
      Width="400" 
      Height="28" 
      SelectedIndex="1" 
      FontSize="12" 
      Margin="40,0,0,0"/> 
      </StackPanel> 
      <StackPanel Orientation="Horizontal" Margin="10,2,0,0"> 
       <Label 
      Content="Capture filter:" 
      Margin="0,3,0,0"/> 
       <TextBox 
      Name="tbSnifferFilter" 
      Width="399" 
      Height="28" 
      TextChanged="tbSnifferFilter_TextChanged" 
      LostFocus="tbSnifferFilter_LostFocus" 
      Margin="21,0,0,0"> 
        <TextBox.ToolTip> 
         <TextBlock> 
       The expression selects which packets will be dumped. 
       <LineBreak /> 
       If no expression is given, all packets on the net will be accepte, 
       <LineBreak /> 
       Otherwise, only packets for which expression is `true' will be accepted. 
         </TextBlock> 
        </TextBox.ToolTip> 
       </TextBox> 
      </StackPanel> 
      <StackPanel Orientation="Horizontal" Margin="10,3,0,0"> 
       <Label 
     Content="Capture file:" 
     Margin="0,3,0,0"/> 
       <TextBox 
      Name="tbSnifferCaptureFile" 
      Width="365" 
      Height="28" 
      ToolTip="Capture file name." 
      TextChanged="tbSnifferFilter_TextChanged" 
      IsReadOnly="True" 
      Margin="29,0,0,0"/> 
       <Button 
      Name="btnSaveCaptureFile" 
      Content="..." 
      Width="32" 
      Height="28" 
      ToolTip="Select a file to which captured data will be wirtten."          
      Click="btnSaveCaptureFile_Click" 
      GotMouseCapture="btnSaveCaptureFile_GotMouseCapture" 
      LostMouseCapture="btnSaveCaptureFile_LostMouseCapture"          
      Margin="3,0,0,0"/> 
      </StackPanel> 
      <StackPanel Orientation="Horizontal" Margin="10,3,0,0"> 
       <Label 
      Content="Packet length:" 
      Margin="0,1,0,0"/> 
       <Controls:NumericUpDown 
      Name="nudSnoplen" 
      Minimum="0" 
      Maximum="65535" 
      Value="65535" 
      StringFormat="N0" 
      MinWidth="50" 
      HideUpDownButtons="True" 
      Width="20" 
      Height="28" 
      ToolTip="Length of the packet that has to be retained." 
      Margin="19,0,0,0" /> 
       <Label 
      Content="bytes" 
      Margin="0,2,0,0"/> 
       <CheckBox 
      Name="cbPromiscuousMode" 
      Content="Promiscuous mode" 
      FontFamily="Ariel" 
      VerticalAlignment="Top" 
      IsChecked="True" 
      Height="25" 
      Margin="20,1,0,0"> 
        <CheckBox.ToolTip> 
         <TextBlock> 
       In normal operation, an adapter only captures packets from the network that, 
       <LineBreak /> 
       are destined to it, the packets exchanged by other hosts are therefore ignored. 
       <LineBreak /> 
       Instead, when the adapter is in promiscuous mode it captures all packets, 
       <LineBreak /> 
       whether they are destined to it or not. 
         </TextBlock> 
        </CheckBox.ToolTip> 
       </CheckBox> 
      </StackPanel> 
     </StackPanel> 
    </Border> 
</Grid> 

enter image description here

그래서 난 내 LabelCornerRadius을 설정할와 나는 다른 Border 안에이 Label를 넣어하려고하지만이 보인다 The property "Child" can only be set once.Label 코너를 돌리는 방법에 대한 제안이 있으십니까?

그래서 내가 설정하려는 내 LabelCornerRadius와 내가 다른 Border 안에이 Label를 넣어하려고하지만 The property "Child" can only be set once. 어떤 제안이 어떻게 내 Label 모서리를 라운드하는 것 같다?

답변

1

다음을 스타일에 추가하면 라벨에 둥근 모서리가 생깁니다. 나는 그것을 임의로 "3"으로 설정했지만, 필요에 따라 그것을 설정할 수 있습니다.

<Window.Resources> 
    <Style x:Key="MyLabelStyle" TargetType="Label"> 
     <Setter Property="Template"> 
     <Setter.Value> 
    <ControlTemplate TargetType="{x:Type Label}"> 
     <Border BorderBrush="{TemplateBinding BorderBrush}" 
      BorderThickness="{TemplateBinding BorderThickness}" 
      Background="{TemplateBinding Background}" 
      Padding="{TemplateBinding Padding}" 
      SnapsToDevicePixels="true" 
      CornerRadius="3"> 
      <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
     </Border> 
     <ControlTemplate.Triggers> 
      <Trigger Property="IsEnabled" Value="false"> 
       <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
      </Trigger> 
     </ControlTemplate.Triggers> 
    </ControlTemplate> 
</Setter.Value> 
</Setter> 
    </Style> 
</Window.Resources> 

<Label Style="{StaticResource MyLabelStyle}"></Label> 
+0

정확히이 코드를 넣어야하는 위치는 어디입니까? – user979033

+0

내 코드를 편집했습니다. 바로 확인해보세요. –

0

당신이 당신의 LabelBorder

<Border BorderThickness="1,1,1,0" 
     BorderBrush="Gray" 
     CornerRadius="5,5,0,0"> 
    <Border Margin="10,-18,0,0" 
      Background="#FF7AA0CD" 
      BorderBrush="Gray" 
      Height="25" 
      CornerRadius="5" 
      Width="60" 
      HorizontalAlignment="Left"> 
    <Label BorderThickness="1" 
      Foreground="Gainsboro" 
      Content=" Options"/> 
    </Border> 
</Border> 

에 넣어 = "{정적 리소스 MyLabelStyle}"windows.resources로 및 레이블 스타일에 위의 코드를 추가 그러나 가장 좋은 방법은 기본 GroupBox 템플릿을 스타일링하는 것입니다.