NLog ルールのログ レベルを変更するオプションをユーザーに提供する必要があります。
12 のルールがあり、それぞれに独自のログ レベルがあります。
WPF でこのオプションを提供するには、どのコントロールを使用することをお勧めしますか?
NLog ルールのログ レベルを変更するオプションをユーザーに提供する必要があります。
12 のルールがあり、それぞれに独自のログ レベルがあります。
WPF でこのオプションを提供するには、どのコントロールを使用することをお勧めしますか?
私は NLog に詳しくありませんが、あらかじめ決められた少数のオプションから選択する必要がある場合は、aComboBox
が最適な UI 要素であると思います。
あなたは 12 のログ レベルがあると言いました。その場合、ItemsControl
すべての UI 要素を自分で作成するのではなく、これらの項目を実際に表示するために を使用するのが最も理にかなっています。
<Window x:Class="MiscSamples.LogLevelsSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="LogLevels" Height="300" Width="300">
<ItemsControl ItemsSource="{Binding LogRules}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Width="100" Margin="2" Text="{Binding Name}"/>
<ComboBox ItemsSource="{Binding DataContext.LogLevels, RelativeSource={RelativeSource AncestorType=Window}}"
SelectedItem="{Binding LogLevel}" Width="100" Margin="2"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Window>
コードビハインド:
public partial class LogLevelsSample : Window
{
public LogLevelsSample()
{
InitializeComponent();
DataContext = new LogSettingsViewModel();
}
}
ビューモデル:
public class LogSettingsViewModel
{
public List<LogLevels> LogLevels { get; set; }
public List<LogRule> LogRules { get; set; }
public LogSettingsViewModel()
{
LogLevels = Enum.GetValues(typeof (LogLevels)).OfType<LogLevels>().ToList();
LogRules = Enumerable.Range(1, 12).Select(x => new LogRule()
{
Name = "Log Rule " + x.ToString(),
LogLevel = MiscSamples.LogLevels.Debug
}).ToList();
}
}
データ項目:
public class LogRule
{
public string Name { get; set; }
public LogLevels LogLevel { get; set; }
}
public enum LogLevels
{
Trace,
Debug,
Warn,
Info,
Error,
Fatal
}
結果:
注意事項:
DataContext
すべての XAML バインディングが解決されるプロパティです。