0

I'm trying to bind the system.io.WatcherChangeTypes enum to the itemsource of a combobox, however the XAML editor can't seem to find the enum in the namespace. I'm guessing i'm overlooking something simpel but hopefully someone could help me out.

Samplecode:

 <Window
    x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:EnumBindingTest"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:sysIO="clr-namespace:System.IO;assembly=WindowsBase"
    Title="MainWindow"
    Width="200"
    Height="100"
    mc:Ignorable="d">
    <Grid>
        <!--  This Works  -->
        <ComboBox
            Width="120"
            HorizontalAlignment="Center"
            VerticalAlignment="Top"
            ItemsSource="{Binding Source={x:Static Fonts.SystemFontFamilies}}" />

        <!--  This Doesn't Works  -->
        <ComboBox
            Width="120"
            HorizontalAlignment="Center"
            VerticalAlignment="Bottom"
            ItemsSource="{Binding Source={x:Static sysIO:WatcherChangeTypes}}" />
    </Grid>
</Window>

I know the WatcherChangeTypes is in the namespace System.IO, See: https://learn.microsoft.com/en-us/dotnet/api/system.io.watcherchangetypes?view=netframework-4.8

Gforse
  • 323
  • 3
  • 20
  • The binding to Fonts.SystemFontFamilies works because it's a collection, not an enum. See the answer to the original question for how to bind to a collection of all values of an enum type. – Clemens May 07 '19 at 12:46
  • Hi Clemens, Thanks for your quick post and refering me to the topic. I already found this one and know how to bind Enums, however... let me put the question like this: How can i find the right namespace in XAML to get and bind a enum from? I did this before wil system enums but it seems that this one cannot be found? A dirty workaround would be copy the system enum and create a local one and then bind to that one... – Gforse May 07 '19 at 13:49
  • Note that `WatcherChangeTypes` seems to be in `System.IO.FileSystem.Watcher.dll` – Clemens May 07 '19 at 14:19

0 Answers0