2017-01-05 11 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> 
: あなたはそのようなものを作成することができます
関連する問題