wpf mvvm模式下CommandParameter传递多参
CommandParameter一般只允許設置一次,所以如果要傳遞多參數(shù),就要稍微處理一下。我暫時還沒找到更好的方案,下面介紹的這個方案我是目前在用的方案,但給人的感覺總是有些別扭,不像一個正統(tǒng)的解決方案:
?? <Button.CommandParameter>
??????????????? <MultiBinding Converter="{StaticResource MultiParamterConverter}">
??????????????????? <Binding Path="ID"/>
??????????????????? <Binding Path="Name"/>
??????????????? </MultiBinding>
??????????? </Button.CommandParameter>
轉(zhuǎn)換器要這么寫:
?public class MultiParamterConverter : IMultiValueConverter
??? {
??????? public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
??????? {
??????????? //必須新new一個,否則拿不到數(shù)據(jù),因為values在返回之后,就會被清空了
??????????? return values.Clone();
??????? }
??????? public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
??????? {
??????????? throw new NotImplementedException();
??????? }
??? }
轉(zhuǎn)載于:https://www.cnblogs.com/lonelyxmas/p/10147181.html
總結(jié)
以上是生活随笔為你收集整理的wpf mvvm模式下CommandParameter传递多参的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中介者模式(Mediator Patte
- 下一篇: .net core 中使用httpcli