Cześć, może ktoś będzie w stanie pomóc mi rozwiązać problem z którym już od jakiegoś czasu się męczę
Mianowicie chce po prostu do ComboBox wstawić listę elementów z kodu źródłowego. Robię to w taki sposób:
Okno WPF
<mah:MetroWindow x:Class="AlarmConfiguration.Lines.LineSettingsRadio"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:AlarmConfiguration.Lines"
xmlns:resx="clr-namespace:AlarmConfiguration.Resources" d:DataContext="{d:DesignInstance Type=local:Line}"
mc:Ignorable="d"
Title="{x:Static resx:Translations.RemoteConfig}" Height="220" Width="320" Closed="MetroWindow_Closed">
<StackPanel Orientation="Vertical">
<CheckBox Content="Linia 24h"/>
<ComboBox SelectedItem="{Binding Type, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}">
<Style TargetType="{x:Type ComboBox}">
<Setter Property="ItemsSource" Value="{Binding LineTypes}" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</ComboBox>
</StackPanel>
</mah:MetroWindow>
Dane w pliku Lines i znajdujące się w takiej przestrzeni
[MarshalAs(UnmanagedType.I1)] public LineType lineType = LineType.NotUsed;
public string Type
{
get => Converter.EnumDescription.GetDescription(thisLine.lineType);
set
{
foreach (var lineType in Enum.GetValues(typeof(LineType)).Cast<LineType>())
{
if (Converter.EnumDescription.GetDescription(lineType) == value)
{
thisLine.lineType = lineType;
break;
}
}
OnPropertyChanged();
}
}
public static IEnumerable<string> LineTypes
{
get
{
yield return Converter.EnumDescription.GetDescription(LineType.NotUsed);
foreach (var lineType in Enum.GetValues(typeof(LineType)).Cast<LineType>())
{
if(lineType != LineType.NotUsed)
yield return Converter.EnumDescription.GetDescription(lineType);
}
}
}
public enum LineType : byte
{
[LocalizedDescription("LineTypeEntryExit1", typeof(Translations))] Enter_Exit_1 = 0,
[LocalizedDescription("LineTypeEntryExit2", typeof(Translations))] Enter_Exit_2 = 1,
[LocalizedDescription("LineTypeInternal", typeof(Translations))] Internal = 2,
[LocalizedDescription("LineTypeInstant", typeof(Translations))] Instant = 3,
//[LocalizedDescription("LineTypeJointly", typeof(Translations))] Jointly = 4,
[LocalizedDescription("LineTypeNotUsed", typeof(Translations))] NotUsed = 5,
[LocalizedDescription("LineTypeFire24", typeof(Translations))] Fire24 = 6,
[LocalizedDescription("LineTypeBreakingIn24", typeof(Translations))] BreakingIn24 = 7,
}
W efekcie obecnie mam w ComboBoxie tekst: System.Windows.Style