2016-04-05 46 views
0

我們正在與WPF工作在VS 2015年要實現以下控制TextDecorations屬性: - 巴頓 - 複選框 - 標籤 - 單選TextBlock是否可以通過Style使用TextDecorations屬性?

一種方式是實現一個TextBlock控制作爲內容這樣的:

<CheckBox x:Name="checkbox"> 
    <TextBlock> 
     CheckBox<Run TextDecorations="Underline"></Run> 
    </TextBlock> 
</CheckBox> 

然後 - 代碼 - 這將是可以調整的性質:

FrameworkElement fe = this.checkbox; 
if (fe.GetType().GetProperty("Content") != null && fe.GetType().GetProperty("Content").GetValue(fe).GetType() == typeof(TextBlock)) 
{ 
    FrameworkElement tbb = (FrameworkElement)fe.GetType().GetProperty("Content").GetValue(fe); 
    tbb.GetType().GetProperty("TextDecorations").SetValue(tbb, TextDecorations.Underline); 
} 

但我們真正想要的是通過一種風格實現這樣的例子:

<Style x:Key="checkboxStyle" TargetType="{x:Type CheckBox}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate> 
       <Grid x:Name="container"> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="2*"/> 
         <RowDefinition/> 
        </Grid.RowDefinitions> 
        <TextBlock x:Name="display" 
             Grid.Row="1" 
             Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" 
             Margin="5,2,5,2"/> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

這是可能的,沒有人知道它的例子嗎?

由於提前, 帕特里克

+0

將IR工作,爲您添加TextDecorations="Underline"? – Gopichandar

+0

不幸的不是我們想要的。我們需要在複選框(每個示例)內部實現一個TextBlock,以便我們能夠在運行時設置TextDecorations屬性。 –

+0

你不清楚。你會請更新你的確切目標。 – Gopichandar

回答

0

就在您的TextBlockControlTemplate

<TextBlock TextDecorations="Underline" x:Name="display" Grid.Row="1" Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" Margin="5,2,5,2"/> 
相關問題