2017-01-05 1 views
0

텍스트 상자를 포함하는 DataTemplate을 정의했습니다. "장갑 모드"에서는 큰 글꼴/minHeight가 필요하므로 터치 스크린이 잘 작동하지만 "사무실 모드"에서는 다른 값을 원합니다. 나는 이것이 가능해야한다고 믿지만 그것을 이해할 수는 없다.DataTemplate의 ThemeResource를 어떻게 재설정 할 수 있습니까?

코드의 테마를 수정하려면 어떻게해야합니까? 또는 이것이 완전히 잘못 되었다면 어떻게해야합니까?

스타일 :

<Style x:Key="GloveTextBoxStyle" TargetType="TextBox"> 
    <Setter Property="FontSize" Value="30"/> 
    <Setter Property="MinHeight" Value="60"/> 
</Style> 
<Style x:Key="OfficeTextBoxStyle" TargetType="TextBox"> 
    <Setter Property="FontSize" Value="14"/> 
    <Setter Property="MinHeight" Value="30"/> 
</Style> 

DataTemplate을 :

<DataTemplate x:Key="InspectionItemStringTemplate" x:DataType="data:InspectionItem"><TextBox Text="{x:Bind NewValue,Mode=TwoWay}" 
        x:Name="MyTextBox" 
        x:Phase="1" Style="{ThemeResource GloveTextBoxStyle}"/></DataTemplate> 

답변

2

무엇 IValueConverter 어떻습니까? 당신은 그런 걸 만들 수 있습니다

public class TextBoxStyleConverter : IValueConverter 
{ 
    public Style GloveTextBoxStyle { get; set; } 

    public Style OfficeTextBoxStyle { get; set; } 

    public object Convert(object value, Type targetType, object parameter, string language) 
    {     
     // analyze binded value and return needed style 
     return condition ? GloveTextBoxStyle : OfficeTextBoxStyle; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, string language) 
    { 
     throw new NotImplementedException(); 
    } 
} 

하고 XAML 코드를

<local:TextBoxStyleConverter x:Key="TextBoxStyleConverter"> 
     <local:TextBoxStyleConverter.GloveTextBoxStyle> 
      <Style TargetType="TextBox"> 
       <Setter Property="FontSize" Value="30"/> 
       <Setter Property="MinHeight" Value="60"/> 
      </Style> 
     </local:TextBoxStyleConverter.GloveTextBoxStyle> 
     <local:TextBoxStyleConverter.OfficeTextBoxStyle> 
      <Style TargetType="TextBox"> 
       <Setter Property="FontSize" Value="14"/> 
       <Setter Property="MinHeight" Value="30"/> 
      </Style> 
     </local:TextBoxStyleConverter.OfficeTextBoxStyle> 
    </local:TextBoxStyleConverter> 


    <DataTemplate x:Key="InspectionItemStringTemplate" 
        x:DataType="data:InspectionItem"> 
     <TextBox Text="{x:Bind NewValue,Mode=TwoWay}" 
       x:Name="MyTextBox" 
       x:Phase="1" 
       Style="{Binding Converter={StaticResource TextBoxStyleConverter}}"/> 
    </DataTemplate> 
관련 문제