2012-03-26 1 views
0

Ich habe eine Enumeration als:Wie eine Art Konverter von String enum der Typ-Bit-Felder implementieren

C#

[Flags] 
public enum FieldStyle 
{ 

    FS_ShadeWords = 0x00000001, 
    FS_WithWords = 0x00000002, 
    FS_WithLetters = 0x00000004, 
    FS_MMDD_YYMM = 0x00000008, 
    FS_T2WordsUnder = 0x00000010, 
    FS_T2Style = 0x00000020, 
    FS_AT1 = 0x00000040, 
    FS_TP1Keying = 0x00000080, 
    FS_T1KeyDate = 0x00000100, 
    FS_H8Date = 0x00000200, 
    FS_AT1Blob = 0x00000400, 
    FS_ThickRight = 0x00000800, 
    FS_ThickLeft = 0x00001000, 
    FS_GreyBase = 0x00002000, 
    FS_C017_Keying = 0x00004000, 
    FS_CT23Date = 0x00008000, 
    FS_TopEdge = 0x00010000, 
    FS_DefaultDate = 0x00020000, 
} 

In einem Stil, den ich eine Eigenschaft wie folgt festlegen müssen:

XAML:

<Setter Property="WhichFieldStyle" Value="FS_DefaultDate,FS_WithWords"/> 

es mit XAML nicht akzeptiert.

Jeder weiß, wie man ein Bit-Feld in XAML setzt ???

+0

Was ist der Fehler Das bekommst du? – casperOne

+0

+0

Das ist kein Fehler. – casperOne

Antwort

0

ich weiß wirklich nicht, was mit Ihrem Code schief geht, aber dieses funktioniert gut

<UserControl x:Class="WpfAppCursorTest.UserControl1" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      x:Name="uc"> 
    <Grid> 
    <TextBox Text="{Binding ElementName=uc, Path=WhichFieldStyle}" /> 
    </Grid> 
</UserControl> 
public partial class UserControl1 : UserControl 
{ 
    public static readonly DependencyProperty WhichFieldStyleProperty = 
    DependencyProperty.Register("WhichFieldStyle", typeof(FieldStyle), typeof(UserControl1), new PropertyMetadata(default(FieldStyle))); 

    public FieldStyle WhichFieldStyle { 
    get { return (FieldStyle)this.GetValue(WhichFieldStyleProperty); } 
    set { this.SetValue(WhichFieldStyleProperty, value); } 
    } 

    public UserControl1() { 
    this.InitializeComponent(); 
    } 
} 
<Window x:Class="WpfAppCursorTest.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:WpfAppCursorTest="clr-namespace:WpfAppCursorTest" 
     Title="MainWindow" 
     Height="350" 
     Width="525"> 
    <Grid> 
    <WpfAppCursorTest:UserControl1 WhichFieldStyle="FS_DefaultDate,FS_WithWords,FS_TP1Keying" /> 
    </Grid> 
</Window> 

enter image description here

hoffe, das hilft