2017-04-17 83 views
-1
var item = new RadioButton { Content = "some_name"}; 
     item.Checked += radioButtonClick; 
     item.Unchecked += radioButtonUnClick; 

實際顯示的是somename。下劃線缺失。爲了解決這個問題,在單選按鈕上使用了以下樣式,但它有副作用。 Radiobutton圖標不可見。單選按鈕文本不顯示下劃線(_)wpf

<Style x:Key="{x:Type RadioButton}" TargetType="{x:Type RadioButton}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type RadioButton}"> 
        <Border Background="{TemplateBinding Background}" 
         BorderThickness="{TemplateBinding BorderThickness}" 
         BorderBrush="{TemplateBinding BorderBrush}" 
         Padding="{TemplateBinding Padding}" 
         SnapsToDevicePixels="true"> 
         <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
             VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
             RecognizesAccessKey="False" 
             SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 
        </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> 

在此先感謝

+1

你實際上是問不同的問題標題,或許重命名將是一個好主意嗎?:) –

+0

,你正在使用這種風格添加單選按鈕的代碼和代碼作爲@Chris建議重命名標題將是個好主意。 – tabby

回答

0

要顯示underscoreradiobutton請使用下面的代碼。

<RadioButton ...... > 
    <TextBlock Text="SELECT_ME" /> 
</RadioButton> 

背後

var item = new RadioButton { Content = new TextBlock { Text = "SELECT_ME" } }; 
+0

謝謝..它的工作! – user2131048