I want to iterate trough my Settings (two settings Files, Settings and Monitor) and Show them in an ItemsControl. The Problem is: I can only bind the DefaultValue (referenced to the Value Bound to the ItemsControl) and not the actual Value.
<UserControl x:Class="ProjectPerformance.Views.Settings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:my="clr-namespace:ProjectPerformance.Views"
xmlns:local="clr-namespace:ProjectPerformance"
xmlns:properties="clr-namespace:ProjectPerformance.Properties"
xmlns:System="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<DataTemplate DataType="{x:Type sys:String}" x:Key="settingstringtemplate">
<Grid Margin="0,2">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Content="{Binding Name}"/>
<TextBox Text="{Binding DefaultValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" />
</Grid>
</DataTemplate>
<DataTemplate DataType="{x:Type sys:Int32}" x:Key="settinginttemplate">
<Grid Margin="0,2">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}" Background="Red"/>
<TextBox Text="{Binding DefaultValue}" Grid.Column="1"/>
</Grid>
</DataTemplate>
<DataTemplate DataType="{x:Type sys:Boolean}" x:Key="settingbooleantemplate">
<Grid Margin="0,2">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}"/>
<CheckBox IsChecked="{Binding DefaultValue, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" />
</Grid>
</DataTemplate>
<local:Settingstemplateselector x:Key="settingstemplateselector"/>
</UserControl.Resources>
<Grid TextElement.FontSize="20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Label Content="Settings" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" FontSize="40" VerticalAlignment="Top"/>
<ScrollViewer Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalScrollBarVisibility="Auto">
<StackPanel>
<Expander FontSize="15">
<Expander.Header>
<TextBlock FontSize="20">General</TextBlock>
</Expander.Header>
<ItemsControl x:Name="lbGeneral" ItemTemplateSelector="{StaticResource settingstemplateselector}" ItemsSource="{Binding Source={x:Static properties:Settings.Default}, Path=Properties}"/>
</Expander>
<Expander FontSize="15">
<Expander.Header>
<TextBlock FontSize="20">Monitor</TextBlock>
</Expander.Header>
<ItemsControl x:Name="lbMonitor" ItemTemplateSelector="{StaticResource settingstemplateselector}" ItemsSource="{Binding Source={x:Static properties:Monitor.Default}, Path=Properties}"/>
</Expander>
<Button x:Name="btnSave" Width="150" Margin="5" HorizontalAlignment="Right" Content="Save" FontSize="15" PreviewMouseLeftButtonDown="btnSave_PreviewMouseLeftButtonDown"/>
<Button x:Name="btnDebug" Width="150" Margin="5" HorizontalAlignment="Right" Content="{Binding Source={x:Static properties:Monitor.Default}, Path=graph_size}" FontSize="15" PreviewMouseLeftButtonDown="btnDebug_PreviewMouseLeftButtonDown"/>
<Button x:Name="btnRestart" Width="150" Margin="5" HorizontalAlignment="Right" Content="Restart App" FontSize="15" PreviewMouseLeftButtonDown="btnRestart_PreviewMouseLeftButtonDown"/>
</StackPanel>
</ScrollViewer>
</Grid>
I think it could Work like this:
<TextBox Text="{Binding Source={x:Static properties:Monitor.Default}, Path={Binding Name}}"/>
But I don't know how to bind a value inside a Binding.
You can bind to to the
PropertyValues
property to get the currentSettingsPropertyValue
values, e.g.:Note that for the
PropertyValues
property to actually return any values, you apparently need to either set a property or retrieve each property first. You could do this dynamically using some reflection: