如何将 2 个值传递给我的 ValueConverters 类?

发布于 2024-10-31 10:07:54 字数 1140 浏览 7 评论 0原文

我的 Xaml 上有这个,我正在传递分配给更改网格单元颜色的值。但我想同时检查输入的变量值,以便我可以根据该值进行更改。如何传递 2 个值,以便我可以在 iconverter 类上设置条件。

<DataGridTextColumn Binding="{Binding Allocated}" Header="Allocated" >
                     <DataGridTextColumn.ElementStyle>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="Background" Value="{Binding Allocated, Converter={StaticResource converter}}"/>
                            </Style>
                        </DataGridTextColumn.ElementStyle>     </DataGridTextColumn>

我的转换器类:

对象 IValueConverter.Convert(对象值,类型 targetType,对象参数,System.Globalization.CultureInfo 文化){

         string input = value.ToString(); 

         switch (input) 
         { 
             case "99":
                 return Brushes.Green;
             case "96":
                 return Brushes.Green;
             case "91":
              default:   
                 return DependencyProperty.UnsetValue; 
         }

    }

块引用

提前致谢!

I have got this on my Xaml , I am passing value allocated to change gridcell colour. But I want to check also at same time Entered variable value so I can change according to that.How can I pass 2 values so I can have conditions on my iconverter class.

<DataGridTextColumn Binding="{Binding Allocated}" Header="Allocated" >
                     <DataGridTextColumn.ElementStyle>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="Background" Value="{Binding Allocated, Converter={StaticResource converter}}"/>
                            </Style>
                        </DataGridTextColumn.ElementStyle>     </DataGridTextColumn>

my Converter class:

object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){

         string input = value.ToString(); 

         switch (input) 
         { 
             case "99":
                 return Brushes.Green;
             case "96":
                 return Brushes.Green;
             case "91":
              default:   
                 return DependencyProperty.UnsetValue; 
         }

    }

Blockquote

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖微凉心微凉 2024-11-07 10:07:54

使用MultiBinding

<DataGridTextColumn.ElementStyle>
    <Style TargetType="{x:Type TextBlock}">
        <Setter Property="Background">
            <Setter.Value>
                <MultiBinding Converter="{StaticResource converter}">
                    <Binding Path="Allocated" />
                    <Binding Path="Entered" />
                </MultiBinding>
            </Setter.Value>
        </Setter>
    </Style>
</DataGridTextColumn.ElementStyle>

并使用您的转换工具IMultiValueConverter

public class MyConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, 
                          object parameter, CultureInfo culture)
    {...

Use MultiBinding:

<DataGridTextColumn.ElementStyle>
    <Style TargetType="{x:Type TextBlock}">
        <Setter Property="Background">
            <Setter.Value>
                <MultiBinding Converter="{StaticResource converter}">
                    <Binding Path="Allocated" />
                    <Binding Path="Entered" />
                </MultiBinding>
            </Setter.Value>
        </Setter>
    </Style>
</DataGridTextColumn.ElementStyle>

and ake your convet implement IMultiValueConverter:

public class MyConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, 
                          object parameter, CultureInfo culture)
    {...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文