相关疑难解决方法(0)

如何将整数传递给ConverterParameter?

我想绑定到一个整数属性:

<RadioButton Content="None"
             IsChecked="{Binding MyProperty,
                         Converter={StaticResource IntToBoolConverter},
                         ConverterParameter=0}" />
Run Code Online (Sandbox Code Playgroud)

我的转换器是:

[ValueConversion(typeof(int), typeof(bool))]
public class IntToBoolConverter : IValueConverter
{
    public object Convert(object value, Type t, object parameter, CultureInfo culture)
    {
        return value.Equals(parameter);
    }

    public object ConvertBack(object value, Type t, object parameter, CultureInfo culture)
    {
        return value.Equals(false) ? DependencyProperty.UnsetValue : parameter;
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是,当我的转换器被调用时,参数是字符串.我需要它是一个整数.当然我可以解析字符串,但我必须这样做吗?

感谢konstantin的任何帮助

wpf binding ivalueconverter

88
推荐指数
3
解决办法
8万
查看次数

在XAML中Path =有什么用?

我在XAML中使用了很多绑定,有时我在绑定中使用path =,有时不使用.在哪些情况下我需要路径=什么时候可以省略这个?

c# wpf xaml binding

22
推荐指数
3
解决办法
2万
查看次数

将SortedList或Dictionary <int,string>添加到ResourceDictionary

有没有办法将SortedList或Dictionary添加到ResourceDictionary并通过XAML使用(并绑定!)它到控件?

我试过这个,但我无法弄清楚如何做到这一点:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:coll="clr-namespace:System.Collections.Generic;assembly=mscorlib">

    <x:Array x:Key="test"
             Type="sys:Object">
        <coll:KeyValuePair>***</coll:KeyValuePair>
    </x:Array>
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

10
推荐指数
1
解决办法
4074
查看次数

WPF绑定如何区分索引器属性和列表元素?

我有一个绑定的形式:

Path=SpecialCollection[0]
Run Code Online (Sandbox Code Playgroud)

SpecialCollection类扩展了ObservableCollection并具有索引器属性.

public T this[string propertyValue]
{
    get
    {
        // do stuff
        return default(T);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是绑定尝试获取索引器属性值,而不是返回集合中的第0项.有没有办法强制绑定将0视为一个整数,因此它返回一个集合元素,而不是调用集合的索引器属性的getter?

c# data-binding indexing wpf xaml

6
推荐指数
1
解决办法
3505
查看次数

标签 统计

wpf ×4

c# ×3

xaml ×3

binding ×2

data-binding ×1

indexing ×1

ivalueconverter ×1