• WPF Converter 使用复杂参数的方法



    Step 1
    在WPF的C#代码文件中给定义复杂类型的变量,并给其赋值;
    Sample code: List<User>lsUser=。。。。
    Setp 2
    在 C#代码对应的XAML 中将此复杂参数定义为资源;
    Sample code:
    <Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:SDKSample"
    x:Class="SDKSample.Window1"
    Width="400"
    Height="280"
    Title="MultiBinding Sample">

    <Window.Resources>
    <c:lsUser x:Key="userList"/>
    ...

    </Window.Resources>

    这里的命名空间 C 是你的复杂参数所在的命名空间;
    Step 3

    <UserControl.Resources>
    <app:UserManager x:Key="StaticUsers"/>
    <app:UserNameConverter x:Key="UsrConverter"/>
    </UserControl.Resources>
    <TextBox Text="{Binding XXXX,Converter={StaticResource UsrConverter},
    ConverterParameter={StaticResource userList }}" />

    Step 4 Converter 里对参数的使用

    public class UserNameConverter : IValueConverter
    {
    public object IValueConverter.Convert(object value, Type targetType,object parameter, CultureInfo culture)
    {
    List<User> usrs = parameter as List<User>;
    ...
    }
    }

  • 相关阅读:
    玩游戏(dfs)
    Find them, Catch them(并查集)
    Shredding Company(dfs)
    Sudoku(dfs)
    Network Saboteur(dfs)
    棋盘问题(dfs)
    Curling 2.0(dfs)
    A Knight's Journey(dfs)
    15. 3Sum
    12. Integer to Roman
  • 原文地址:https://www.cnblogs.com/quietwalk/p/3531590.html
Copyright © 2020-2023  润新知