开发者

WPF enumeration value as ObjectDataProvider's method parameter

开发者 https://www.devze.com 2023-01-17 07:30 出处:网络
I want to pass for as a parameter for the GetValues method from MyItemSourceProvide开发者_如何学Pythonr a concrete value of MyEnum. How to write it please?

I want to pass for as a parameter for the GetValues method from MyItemSourceProvide开发者_如何学Pythonr a concrete value of MyEnum. How to write it please?

<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type local:MyItemSourceProvider}">
    <ObjectDataProvider.MethodParameters>
        <!-- ENUM value (e.g. MyEnum.Record1) -->       
    </ObjectDataProvider.MethodParameters>        
</ObjectDataProvider>

method:

public System.Collections.IEnumerable GetValues(MyEnum key) {}
public enum MyEnum {Record1, ...}


You can implement it as following:

<ObjectDataProvider MethodName="GetValues" 
                    ObjectType="{x:Type local:MyItemSourceProvider}" 
                    x:Key="getValues">
    <ObjectDataProvider.MethodParameters>
        <local:MyEnum>Record1</local:MyEnum>
    </ObjectDataProvider.MethodParameters>
</ObjectDataProvider>

or you can also do it in this way:

<ObjectDataProvider MethodName="GetValues" 
                    ObjectType="{x:Type local:MyItemSourceProvider}" 
                    x:Key="getValues">
    <ObjectDataProvider.MethodParameters>
        <x:Static Member="local:MyEnum.Record1" />
    </ObjectDataProvider.MethodParameters>
</ObjectDataProvider>

with:

public enum MyEnum {Record1, Record2, ...}


Try this:

<Window.Resources>    
  <local:MyEnum x:Key="valueToPassIn">Record1</local:MyEnum>
  <x:Type x:Key="typeToPassIn" TypeName="local:MyEnum" />      

  <ObjectDataProvider MethodName="GetValues"        
      ObjectType="{x:Type sys:Enum}"        
      x:Key="ExampleEnumValues"
      MethodParameters="{StaticResource valueToPassIn}">        
   </ObjectDataProvider>
 </Window.Resources>


You may have already found answer. If not you can look here -

http://msdn.microsoft.com/en-us/library/bb613576.aspx

Or

<Window x:Class="SimpleXmlDataSourceExample.MainWindow2"
    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:local="clr-namespace:SimpleXmlDataSourceExample"
    Title="MainWindow2" Height="300" Width="403">
<Window.Resources>
    <ObjectDataProvider x:Key="deptEnumSource" ObjectType="{x:Type Sys:Enum}" MethodName="GetValues" >
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="local:DeptEnum"></x:Type>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</Window.Resources>
<Grid>
    <ComboBox Height="23" HorizontalAlignment="Left" Margin="69,68,0,0" Name="comboBox1" 
              VerticalAlignment="Top" 
              Width="156"  
              ItemsSource="{Binding Source={StaticResource deptEnumSource}}"  
              >
    </ComboBox>
</Grid>

and in this link as well:

http://wpfgrid.blogspot.com/2013/01/v-behaviorurldefaultvmlo_10.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号