This is my Employee class and its collection.
public class Employee
{
public string LastName { get; set; }
public string FirstName { get; set; }
public bool IsHardWorking { get; set; }
public string Description { get; set; }
}
List<Employee> Employees = new List<Employee>()
{
new Employee() { IsHardWorking = false, LastName = "Silly", FirstName = "Dude", Description= "this due is a mess" },
new Employee() { IsHardWorking = true, LastName = "Mean", FirstName = "Person", Description= "funny" },
new Employee() { IsHardWorking = false, LastName = "New", FirstName = "Friend", Description= "let her go in next round of layoffs" },
new Employee() { IsHardWorking = true, LastName = "My", FirstName = "Buddy", Description= "simply no comments" },
};
The data is shown using a data template shown below.
<Grid Loaded="DataLoaded">
<Grid.RowDefinitions>
<RowDefinition Height="6*" />
<RowDefinition />
</Grid.RowDefinitions>
<ListBox x:Name="lst1" Grid.Row="0" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="9*" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" Grid.Column="0" HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal">
<Label FontFamily="Tahoma" FontSize="12" VerticalAlignment="Bottom" Content="Last Name" />
<Label FontFamily="Tahoma" FontSize="18" VerticalAlignment="Bottom" Content="{Binding LastName}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label FontFamily="Tahoma" FontSize="12" VerticalAlignment="Bottom" Content="First Name" />
<Label FontFamily="Tahoma" FontSize="18" VerticalAlignment="Bottom" Content="{Binding FirstName}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label FontFamily="Tahoma" FontSize="12" VerticalAlignment="Bottom" Content="Details" />
<Label FontFamily="Tahoma" FontSize="18" VerticalAlignment="Bottom" Content="{Binding Description}" />
</StackPanel>
</StackPanel>
<Image Source="{Binding IsHardWorking, Converter={StaticResource valueToImageConverter}}" Height="50" Grid.Column="1" HorizontalAlignment="Right" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="5" Grid.Row="1" >
<Button x:Name="btnClose" Content="Close" Margin="5" Width="50" />
</StackPanel>
</Grid>
Here is how it looks.
My problem is that I want the image column should be right justified with a fixed width. First column is assigned most of the width (9*) but I don't know how to make it look like a column. Any ideas
UPDATE
After implementing #FlatEric suggestion, below is what I am getting.
I still have lot of white space on the right side (marked with yellow rectangle). I tried to set Margin to 0 for image but that doesn't change anything.
To make all images aligned in one column you can set the SharedSizeGroup property in the ColumnDefinitions of the Grid in the DataTemplate:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="9*" SharedSizeGroup="A" />
<ColumnDefinition Width="*" SharedSizeGroup="B" />
</Grid.ColumnDefinitions>
Then set Grid.IsSharedSizeScope="True" in the ListBox
<ListBox x:Name="lst1" Grid.Row="0" Grid.IsSharedSizeScope="True" >
Edit:
To remove the space on the right:
Set ShareSizeGroup only for the second column
Add HorizontalContentAlignment="Stretch" to the ListBox
Just add HorizontalContentAlignment='Stretch' to your ListBox element. Unless you have something unusual in your valueToImageConverter that should work. It shouldn't be necessary to use SharedSizeGroup.
Related
This is my object type:
public class selectedLevel
{
public string Level
{
get;
set;
}
public string PlanetSelected
{
get; set;
}
public string houseDetails
{
get;
set;
}
}
This is my itemTemplate:
<ItemsControl x:Name="LevelDetails" Margin="-464,416,120,-484" BorderBrush ="Black" ItemsSource="{Binding selectedLevels}" Grid.ColumnSpan="3" HorizontalContentAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Col1" />
<ColumnDefinition SharedSizeGroup="Col2" />
<ColumnDefinition SharedSizeGroup="Col3" />
<ColumnDefinition SharedSizeGroup="Col4" />
<ColumnDefinition SharedSizeGroup="Col5" />
<ColumnDefinition SharedSizeGroup="Col6" />
<ColumnDefinition SharedSizeGroup="Col7" />
<ColumnDefinition SharedSizeGroup="Col8" />
<ColumnDefinition SharedSizeGroup="Col9" />
<ColumnDefinition SharedSizeGroup="Col10"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="Row1"/>
<RowDefinition SharedSizeGroup="Row2"/>
<RowDefinition SharedSizeGroup="Row3"/>
</Grid.RowDefinitions>
<Label x:Name="LevelName" Grid.Row="0" Content="{Binding Level}" HorizontalContentAlignment="Center" FontWeight="Bold" FontSize="16" BorderBrush="Black" BorderThickness="1" Background="{x:Null}"/>
<Label x:Name="PlanetName" Grid.Row="1" Content="{Binding PlanetSelected}" FontSize="14" Foreground="Red" BorderBrush="Black" FontWeight="Bold" HorizontalContentAlignment="Center" BorderThickness="1" />
<Label x:Name="LevelDetails" Grid.Row="2" HorizontalContentAlignment="Center" Content="{Binding houseDetails}" FontSize="14" BorderBrush="Black" FontWeight="Bold" BorderThickness="1" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
The User control is bound with an object with an observable collection of type selectedLevel(shown at the top).
I am adding the properties of SelectedLevels in a view model as follows:
selectedLevels.Add(new selectedLevel
{
Level = "Mahadasha",
PlanetSelected = Mahadashas[0].rulerName,
houseDetails = indicesList[0] + ", " + indicesList[1] + ", " + indicesList[2]
});
I am trying to get different colors for indicesList[0], indicesList[1] and indicesList[2] in 3rd label which is bound with houseDetails but I can only change full text color and not a part of it.
I am totally lost here. Can I get some assistance on how to set different colors to parts of string?
It's simple, first you need to separate the houseDetails property into 3 strings, something similar to this:
public class selectedLevel
{
public string Level { get; set; }
public string PlanetSelected { get; set; }
public string houseDetails1 { get; set; }
public string houseDetails2 { get; set; }
public string houseDetails3 { get; set; }
}
Then you can use a TextBlock wrapped by a Border instead of the third Label and use Runs inside it to pick a different color for each one and bind them to the corresponding properties:
<Border HorizontalAlignment="Center" BorderBrush="Black" BorderThickness="1">
<TextBlock x:Name="LevelDetails" Grid.Row="2" FontSize="14" FontWeight="Bold">
<Run Text="{Binding houseDetails1}" Foreground="Red"/>,
<Run Text="{Binding houseDetails2}" Foreground="Green"/>,
<Run Text="{Binding houseDetails3}" Foreground="Blue"/>
</TextBlock>
</Border>
And then in the view model:
selectedLevels.Add(new selectedLevel
{
Level = "Mahadasha",
PlanetSelected = Mahadashas[0].rulerName,
houseDetails1 = indicesList[0],
houseDetails2 = indicesList[1],
houseDetails3 = indicesList[2]
});
I've already searched and read from several posts but I couldn't find what I am doing wrong.
I have a ComboBox with an ObservableCollection<string> Available_COMPorts as ItemsSource.
On SelectedValue I binded a string named SelectedCOMPort with Mode = TwoWay.
<Label Content="Porta COM: "></Label>
<ComboBox ItemsSource="{Binding Available_COMPorts}"
SelectedValue="{Binding SelectedCOMPort, Mode=TwoWay}" />
After bofere the combobox, I have a Label displaying the SelectedCOMPort
<Label Content="Status: " />
<Label Content="{Binding SelectedCOMPort}" Foreground="Red" />
I have made both Available_COMPorts and SelectedCOMPort with INotifyPropertyChanged. On my ViewModel Initialization, I filled the Available_COMPorts with the three SerialPort strings available ("COM6", "COM5", "COM4") and set SelectedCOMPort = "Available_COMPorts[0]" ("COM6").
When I Run the code, ComboBox has the three itens, the selected item is "COM6" and the label shows "COM6" (everything is fine). Then I select "COM5" and the label updates it's value to "COM5". This is presented on the following pictures.
The problem is when I try to access SelectedCOMPort on the ViewModel, as I need the selected item to connect on my SerialPort. The SelectedCOMPort is always as the default value "COM6". I try to access the SelectedCOMPorton the connect click command.
Debbuging, using Breakpoints on INotifyProperty functions I realized that the binding property seems to be working fine, but when it leaves INotifyProperty the value goes back to default.
Why is that happening? I've tryed several approachs and none worked for me.
Following is my ViewModel and BaseViewModel with INotifyProperty:
BaseViewModel : INotifyPropertyChanged
public class BaseViewModel : INotifyPropertyChanged
{
#region PropertyChange
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
protected void SetProperty<T>(ref T backingField, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(backingField, value)) return;
backingField = value;
OnPropertyChanged(propertyName);
}
#endregion
}
ViewModel
public class LiveGraphViewModel : BaseViewModel
{
public ConnectButtonCommand ConnectButtonCommand { get; set; }
private ObservableCollection<string> _availableCOMPorts;
private string _selectedCOMPort;
public ObservableCollection<string> Available_COMPorts
{
get { return _availableCOMPorts; }
set { SetProperty(ref _availableCOMPorts, value); }
}
public string SelectedCOMPort
{
get { return _selectedCOMPort; }
set { SetProperty(ref _selectedCOMPort, value); }
}
public LiveGraphViewModel()
{
this.ConnectButtonCommand = new ConnectButtonCommand(this);
ObservableCollection<string> TempCOM = new ObservableCollection<string>();
foreach (string comport in SerialPort.GetPortNames())
TempCOM.Add(comport);
Available_COMPorts = TempCOM;
if(Available_COMPorts.Count > 0)
SelectedCOMPort = Available_COMPorts[0];
}
public void ConnectButton()
{
if (SelectedCOMPort == "COM5")
Connect(SelectedCOMPort);
}
}
LiveGraphView XAML
<UserControl x:Class="SmartAthleticsWPF.Views.LiveGraphView"
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:local="clr-namespace:SmartAthleticsWPF.Views"
xmlns:viewmodels="clr-namespace:SmartAthleticsWPF.ViewModels"
xmlns:commands="clr-namespace:SmartAthleticsWPF.Commands"
xmlns:syncfusion="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF"
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<viewmodels:LiveGraphViewModel x:Key="LIVviewModel"/>
</UserControl.Resources>
<Grid Background="#EDEDED">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.01*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.01*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.1*"/>
<RowDefinition Height="1.2*"/>
<RowDefinition Height="2*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="0.1*"/>
</Grid.RowDefinitions>
<!--LIVE GRAPH BORDER-->
<Border Grid.Row="1" Grid.RowSpan="2"
Grid.Column="1" Grid.ColumnSpan="2"
Margin="5"
BorderBrush="Black"
BorderThickness="2"
CornerRadius="5"
Padding="10,10,30,10"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<DockPanel>
<Label Content="Live Graph"
DockPanel.Dock="Top"
HorizontalAlignment="Center"
Padding="0,5,0,10" FontSize="22"/>
<syncfusion:SfChart x:Name="LiveGraphChart" >
<syncfusion:SfChart.PrimaryAxis>
<syncfusion:NumericalAxis Header="Seconds"
Maximum="{Binding MaxXAxis}"
Minimum="{Binding MinXAxis}"/>
</syncfusion:SfChart.PrimaryAxis>
<syncfusion:SfChart.SecondaryAxis>
<syncfusion:NumericalAxis Header="Kgf"/>
</syncfusion:SfChart.SecondaryAxis>
<syncfusion:SfChart.Series>
<syncfusion:FastLineBitmapSeries ItemsSource="{Binding FyCircularBuffer}"
XBindingPath="XData" YBindingPath="YData"
StrokeThickness="1" Interior="DarkGreen"
ShowTooltip="False" ShowTrackballInfo="False"
IsSeriesVisible="{Binding FyChecked}"/>
<syncfusion:FastLineBitmapSeries ItemsSource="{Binding MyCircularBuffer}"
XBindingPath="XData" YBindingPath="YData"
StrokeThickness="1" Interior="LimeGreen"
ShowTooltip="False" ShowTrackballInfo="False"
IsSeriesVisible="{Binding MyChecked}"/>
<syncfusion:FastLineBitmapSeries ItemsSource="{Binding FxCircularBuffer}"
XBindingPath="XData" YBindingPath="YData"
StrokeThickness="1" Interior="IndianRed"
ShowTooltip="False" ShowTrackballInfo="False"
IsSeriesVisible="{Binding FxChecked}"/>
<syncfusion:FastLineBitmapSeries ItemsSource="{Binding MxCircularBuffer}"
XBindingPath="XData" YBindingPath="YData"
StrokeThickness="1" Interior="Red"
ShowTooltip="False" ShowTrackballInfo="False"
IsSeriesVisible="{Binding MxChecked}"/>
<syncfusion:FastLineBitmapSeries ItemsSource="{Binding FzCircularBuffer}"
XBindingPath="XData" YBindingPath="YData"
StrokeThickness="1" Interior="BlueViolet"
ShowTooltip="False" ShowTrackballInfo="False"
IsSeriesVisible="{Binding FzChecked}"/>
<syncfusion:FastLineBitmapSeries ItemsSource="{Binding MzCircularBuffer}"
XBindingPath="XData" YBindingPath="YData"
StrokeThickness="1" Interior="Blue"
ShowTooltip="False" ShowTrackballInfo="False"
IsSeriesVisible="{Binding MzChecked}"/>
</syncfusion:SfChart.Series>
</syncfusion:SfChart>
</DockPanel>
</Border>
<!--COP BORDER-->
<Border Grid.Row="2"
Grid.Column="3"
Margin="5"
BorderBrush="Black"
BorderThickness="2"
CornerRadius="5"
Padding="10"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<DockPanel>
<Label Content="C O P"
Grid.Column="0" Grid.ColumnSpan="2"
DockPanel.Dock="Top"
HorizontalAlignment="Center"
FontSize="16"
FontWeight="Bold"
Padding="0,0,0,5"/>
<syncfusion:SfChart x:Name="CopChart"
VerticalContentAlignment="Stretch"
HorizontalAlignment="Center"
AreaBorderThickness="5"
AreaBorderBrush="#523B97">
<syncfusion:SfChart.PrimaryAxis>
<syncfusion:NumericalAxis Minimum="-20"
Maximum="20"
Interval="10"
PlotOffset="5"
BorderThickness="0"
TickLineSize="0"
FontSize="12">
<syncfusion:NumericalAxis.AxisLineStyle>
<Style TargetType="Line">
<Setter Property="StrokeThickness" Value="0"/>
</Style>
</syncfusion:NumericalAxis.AxisLineStyle>
</syncfusion:NumericalAxis>
</syncfusion:SfChart.PrimaryAxis>
<syncfusion:SfChart.SecondaryAxis>
<syncfusion:NumericalAxis Minimum="-30"
Maximum="30"
Interval="10"
PlotOffset="5"
BorderThickness="0"
TickLineSize="0"
FontSize="12">
<syncfusion:NumericalAxis.AxisLineStyle>
<Style TargetType="Line">
<Setter Property="StrokeThickness" Value="0"/>
</Style>
</syncfusion:NumericalAxis.AxisLineStyle>
</syncfusion:NumericalAxis>
</syncfusion:SfChart.SecondaryAxis>
<syncfusion:SfChart.Annotations>
<syncfusion:LineAnnotation X1="00" X2="00" Y1="-30" Y2="30"
Stroke="DimGray" StrokeThickness="2" StrokeDashArray="4"/>
<syncfusion:LineAnnotation X1="-20" X2="20" Y1="00" Y2="0"
Stroke="DimGray" StrokeThickness="2" StrokeDashArray="4"/>
</syncfusion:SfChart.Annotations>
<syncfusion:SfChart.Series>
<syncfusion:FastScatterBitmapSeries ItemsSource="{Binding COP_DOT}"
XBindingPath="XData" YBindingPath="YData"
Interior="Red" ScatterHeight="20" ScatterWidth="20"/>
</syncfusion:SfChart.Series>
</syncfusion:SfChart>
</DockPanel>
</Border>
<!--SERIAL BORDER-->
<Border Grid.Row="1"
Grid.Column="3"
Margin="5"
BorderBrush="Black"
BorderThickness="2"
CornerRadius="5"
Padding="15,0,15,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content="Conexão"
Grid.Column="0" Grid.ColumnSpan="2"
DockPanel.Dock="Top"
HorizontalAlignment="Center"
FontSize="16"
FontWeight="Bold"
Padding="0,0,0,5"/>
<DockPanel Grid.Row="1" Grid.ColumnSpan="2" LastChildFill="True">
<Label Content="Porta COM: "></Label>
<ComboBox ItemsSource="{Binding Available_COMPorts}"
SelectedValue="{Binding SelectedCOMPort, Mode=TwoWay}"
Margin="0,0,0,15" />
<!--SelectedItem="{Binding SelectedCOMPort, Mode=TwoWay, diag:PresentationTraceSources.TraceLevel=High}"-->
</DockPanel>
<Button Grid.Row="2" Grid.ColumnSpan="2" Content="Connect/Disconnect" HorizontalAlignment="Stretch" Margin="5"
Command="{Binding Path=ConnectButtonCommand, Source={StaticResource LIVviewModel}}"/>
<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.ColumnSpan="2">
<Label Content="Status: "></Label>
<Label Content="{Binding SelectedCOMPort}" Foreground="Red" />
</StackPanel>
</Grid>
</Border>
<Grid Grid.Row="3"
Grid.Column="1" Grid.ColumnSpan="3"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!--SERIAL BORDER-->
<Border Grid.Column="0"
Margin="5"
BorderBrush="Black"
BorderThickness="2"
CornerRadius="5"
Padding="20,0,20,0">
</Border>
<!--RECORD BORDER-->
<Border Grid.Column="1"
Margin="5"
BorderBrush="Black"
BorderThickness="2"
CornerRadius="5"
Padding="20,0,20,0">
<Grid Margin="5,10,5,10" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1.5*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" Grid.ColumnSpan="2" Margin="0,0,0,10"
Content="Click me" Command="{Binding Path=RecordButtonCommand, Source={StaticResource LIVviewModel}}" />
<Label Content="Record Time (s):"
Grid.Column="0" Grid.Row="1" VerticalAlignment="Center"/>
<TextBlock Text="30" Background="White"
Grid.Column="1" Grid.Row="1"
VerticalAlignment="Center"/>
<Label Content="Name:"
Grid.Column="0" Grid.Row="2" VerticalAlignment="Center"/>
<TextBlock Text="Subject Name"
Grid.Column="1" Grid.Row="2" VerticalAlignment="Center"/>
</Grid>
</Border>
<!--Informações do Gráfico BORDER-->
<Border Grid.Column="2"
Margin="5"
BorderBrush="Black"
BorderThickness="2"
CornerRadius="5"
Padding="10,0,10,0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content="Informações do Gráfico"
Grid.Column="0" Grid.ColumnSpan="6"
HorizontalAlignment="Center"
FontSize="16" FontWeight="Bold" />
<CheckBox Content="Fy"
Grid.Column="0" Grid.Row="1"
FontWeight="ExtraBlack" FontSize="12"
Foreground="DarkGreen"
HorizontalAlignment="Center"
IsChecked="{Binding FyChecked}" />
<CheckBox Content="My"
Grid.Column="1" Grid.Row="1"
FontWeight="ExtraBlack" FontSize="12"
Foreground="LimeGreen"
HorizontalAlignment="Center"
IsChecked="{Binding MyChecked}" />
<CheckBox Content="Fx"
Grid.Column="2" Grid.Row="1"
FontWeight="ExtraBlack" FontSize="12"
Foreground="IndianRed"
HorizontalAlignment="Center"
IsChecked="{Binding FxChecked}" />
<CheckBox Content="Mx"
Grid.Column="3" Grid.Row="1"
FontWeight="ExtraBlack" FontSize="12"
Foreground="Red"
HorizontalAlignment="Center"
IsChecked="{Binding MxChecked}" />
<CheckBox Content="Fz"
Grid.Column="4" Grid.Row="1"
FontWeight="ExtraBlack" FontSize="12"
Foreground="BlueViolet"
HorizontalAlignment="Center"
IsChecked="{Binding FzChecked}" />
<CheckBox Content="Mz"
Grid.Column="5" Grid.Row="1"
FontWeight="ExtraBlack" FontSize="12"
Foreground="Blue"
HorizontalAlignment="Center"
IsChecked="{Binding MzChecked}" />
<DockPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" LastChildFill="True" HorizontalAlignment="Stretch">
<Label Content="Periodo: " VerticalAlignment="Center"/>
<ComboBox Text="30" Background="White" VerticalAlignment="Center"
SelectedIndex="{Binding PeriodSelectedIndex}"> <!--5-->
<ComboBoxItem Content="100 ms" />
<ComboBoxItem Content="500 ms" />
<ComboBoxItem Content="1 s" />
<ComboBoxItem Content="5 s" />
<ComboBoxItem Content="10 s" />
<ComboBoxItem Content="30 s" />
</ComboBox>
</DockPanel>
<DockPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" LastChildFill="True" HorizontalAlignment="Stretch">
<Label Content="Amplitude: " VerticalAlignment="Center"/>
<ComboBox Text="30" Background="White" VerticalAlignment="Center"
SelectedIndex="{Binding AmplitudeSelectedIndex}"> <!--3-->
<ComboBoxItem Content="10"/>
<ComboBoxItem Content="100"/>
<ComboBoxItem Content="500"/>
<ComboBoxItem Content="1000"/>
<ComboBoxItem Content="5000"/>
<ComboBoxItem Content="10000"/>
</ComboBox>
</DockPanel>
<Label Grid.Row="2" Grid.Column="3" Grid.ColumnSpan="3" Content="{Binding PesoKg}" ContentStringFormat="Peso (kg): {0}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Label Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="3" Content="{Binding PesoNw}" ContentStringFormat="Força (N): {0}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</Border>
</Grid>
</Grid>
</UserControl>
Connect Button
public class ConnectButtonCommand : ICommand
{
public LiveGraphViewModel ViewModel { get; set; }
public ConnectButtonCommand(LiveGraphViewModel viewModel)
{
this.ViewModel = viewModel;
}
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
this.ViewModel.ConnectButton();
}
}
DataContext
public partial class LiveGraphView : UserControl
{
private LiveGraphViewModel _vm;
public LiveGraphView()
{
InitializeComponent();
this._vm = new LiveGraphViewModel();
this.DataContext = this._vm;
}
}
As mentioned by #Clemens I had two view model instances at the same time.
One created in the UserControl's constructor (code behind) and other on the XAML Resources.
So, I removed the last one and everything works fine.
<!--
<UserControl.Resources>
<viewmodels:LiveGraphViewModel x:Key="LIVviewModel"/>
</UserControl.Resources>
-->
<Label Content="Porta COM: "></Label>
<ComboBox ItemsSource="{Binding Available_COMPorts}"
SelectedValue="{Binding SelectedCOMPort, Mode=TwoWay}" />
<Button Content="Connect/Disconnect"
Command="{Binding Path=ConnectButtonCommand}" />
Please find below my XAML,
<loc:MultiSelectTreeView Height="295" ScrollViewer.VerticalScrollBarVisibility="Visible" BorderThickness="1" Background="WhiteSmoke" x:Name="GridListEmulation" Grid.Row="2" BorderBrush="Gray" ItemsSource="{Binding EmulationCollection,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Margin="0,2,0,-2"
ItemContainerStyle="{StaticResource MultiSelectTreeViewItemStyle}" SelectedItemChanged="GridListEmulation_SelectedItemChanged">
<TreeView.ItemTemplate >
<HierarchicalDataTemplate ItemsSource="{Binding Items,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" >
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Stream" Width="60"/>
<ColumnDefinition SharedSizeGroup="Port" Width="55"/>
<ColumnDefinition SharedSizeGroup="Device Name" Width="100"/>
<ColumnDefinition SharedSizeGroup="Count" Width="50"/>
<ColumnDefinition SharedSizeGroup="FromMAC" Width="120"/>
<ColumnDefinition SharedSizeGroup="State" Width="60"/>
<ColumnDefinition SharedSizeGroup="MACAddress" Width="120"/>
<ColumnDefinition SharedSizeGroup="EmulationIPv4Address" Width="100"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding StreamId}" Style="{StaticResource TextBlockStyle}"/>
<TextBlock Grid.Column="1" Text="{Binding Port}" Style="{StaticResource TextBlockStyle}"/>
<TextBlock Grid.Column="2" Text="{Binding EmulationDeviceName}" Style="{StaticResource TextBlockStyle}"/>
<TextBlock Grid.Column="3" Text="{Binding SessionCount}" Style="{StaticResource TextBlockStyle}"/>
<TextBlock Grid.Column="4" Text="{Binding SourceMAC}" Style="{StaticResource TextBlockStyle}"/>
<TextBlock Grid.Column="5" Text="{Binding State}" Style="{StaticResource TextBlockStyle}"/>
<TextBlock Grid.Column="6" Text="{Binding SimulatedMAC}" Style="{StaticResource TextBlockStyle}"/>
<TextBlock Grid.Column="7" Text="{Binding EmulationIPv4Address}" Style="{StaticResource TextBlockStyle}"/>
</Grid>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</loc:MultiSelectTreeView>
I am trying to delete a subitem in this multi treeview which is bound to my observable collection as shown below,
tvm.EmulationCollection.RemoveAt(GridListEmulation.Items.IndexOf(subItem));
But i always get the index as -1 for subitem and then gives an exception. Please let me know if any way to get the subitem in the tree view item of the heirarchical data template and delete it? Thanks in advance.
here is a basic example of using a VM to host a tree
public class TreeVM : BindableBase
{
public TreeVM()
{
AddChild = new DelegateCommand(() => Items.Add(new TreeVM() {Parent = this }));
RemoveMe = new DelegateCommand(() => Parent.Items.Remove(this));
}
private string _Text;
public string Text
{
get { return _Text; }
set { SetProperty(ref _Text, value); }
}
private TreeVM _Parent;
public TreeVM Parent
{
get { return _Parent; }
set { SetProperty(ref _Parent, value); }
}
public ObservableCollection<TreeVM> Items { get; } = new ObservableCollection<TreeVM>();
public DelegateCommand AddChild { get; set; }
public DelegateCommand RemoveMe { get; set; }
}
then hosted on this XAML
<StackPanel>
<Button Content="Add" Command="{Binding AddChild}"/>
<TreeView ItemsSource="{Binding Items}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Items}">
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Text}"/>
<Button Content="Add" Command="{Binding AddChild}"/>
<Button Content="Delete" Command="{Binding RemoveMe}"/>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</StackPanel>
as you can see the child is responsible for removing itself from the tree, and this works because your VM knows its parent as well as its children
I'm trying to create an ItemsControl that uses a grid as its ItemsPanel in such a way that it has two columns, where the first columns width is the width of the widest item in that column, and has as may rows needed to display all the items
Basically, I want the following, but somehow within an ItemsControl so that I can bind to a collection of objects:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Label Content="{Binding Items[0].Header}"/>
<TextBox Text="{Binding Items[0].Content}" Grid.Column="1"/>
<Label Content="{Binding Items[1].Header}" Grid.Row="1"/>
<TextBox Text="{Binding Items[1].Content}" Grid.Row="1" Grid.Column="1"/>
<Label Content="{Binding Items[2].Header}" Grid.Row="2"/>
<TextBox Text="{Binding Items[2].Content}" Grid.Row="2" Grid.Column="1"/>
</Grid>
Edit : Rachels answer worked great, here is a working example.
(I moved the Grid.IsSharedSizeScope="True" to the ItemsPanel, not sure if Rachel meant to put it in the ItemTemplate (which didn't work))
namespace WpfApplication23
{
public partial class Window1 : Window
{
public List<Item> Items { get; set; }
public Window1()
{
Items = new List<Item>()
{
new Item(){ Header="Item0", Content="someVal" },
new Item(){ Header="Item1", Content="someVal" },
new Item(){ Header="Item267676", Content="someVal" },
new Item(){ Header="a", Content="someVal" },
new Item(){ Header="bbbbbbbbbbbbbbbbbbbbbbbbbb", Content="someVal" },
new Item(){ Header="ccccccc", Content="someVal" }
};
InitializeComponent();
DataContext = this;
}
}
public class Item
{
public string Header { get; set; }
public string Content { get; set; }
}
}
<Window x:Class="WpfApplication23.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Grid.IsSharedSizeScope="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="ColumnOne" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Content="{Binding Header}"/>
<TextBox Text="{Binding Content}" Grid.Column="1"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Window>
There are multiple problems here for an ItemsControl:
Getting your first column to match the width of the largest item
Generating a dynamic number of rows
Generating more than one item for each iteration of the ItemsControl
The last one is really the biggest problem, because an ItemsControl wraps each ItemTemplate in a ContentPresenter, so there is no default way of creating more than one item in the panel for each Iteration of the ItemsControl. Your end result would look like this:
<Grid>
...
<ContentPresenter>
<Label Content="{Binding Items[0].Header}"/>
<TextBox Text="{Binding Items[0].Content}" Grid.Column="1"/>
</ContentPresenter>
<ContentPresenter>
<Label Content="{Binding Items[1].Header}" Grid.Row="1"/>
<TextBox Text="{Binding Items[1].Content}" Grid.Row="1" Grid.Column="1"/>
</ContentPresenter>
<ContentPresenter>
<Label Content="{Binding Items[2].Header}" Grid.Row="2"/>
<TextBox Text="{Binding Items[2].Content}" Grid.Row="2" Grid.Column="1"/>
</ContentPresenter>
</Grid>
My best suggestion would be to create an ItemTemplate that contains a 1x2 Grid, and use Grid.IsSharedSizeScope to make the width of the first column shared. (The ItemsPanelTemplate would remain the default StackPanel.)
This way, the end result would look like this:
<StackPanel>
<ContentPresenter>
<Grid IsSharedSizeScope="True">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="ColumnOne" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Content="{Binding Header}"/>
<TextBox Text="{Binding Content}" Grid.Column="1"/>
</Grid>
</ContentPresenter>
<ContentPresenter>
<Grid IsSharedSizeScope="True">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="ColumnOne" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Content="{Binding Header}"/>
<TextBox Text="{Binding Content}" Grid.Column="1"/>
</Grid>
</ContentPresenter>
...
</StackPanel>
You can use a ListView
<ListView ItemsSource="{Binding MyList}">
<ListView.View>
<GridView>
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn
Header=""
Width="Auto"
DisplayMemberBinding="{Binding Header}"/>
<GridViewColumn
Header=""
DisplayMemberBinding="{Binding Value}"/>
</GridView>
</ListView.View>
</ListView>
the ColumnHeaderContainerStyle hides the GridViewHeader
I am making a Silverlight 4.0 Navigation Application with Authentication Service to manage users, log in/out and so forth.
I have used the msdn tutorial on this page: http://msdn.microsoft.com/en-us/library/ee942451%28v=vs.91%29.aspx
It works great. I can create users with some custom profile properties and log in and out.
The problem is my create user form. As in the tutorial I have in my service project made a class called NewUser, with data annotations. These seems to work, as if I try to create a user with a invalid field, the creation fails, and i get an exception, with the message that there are validation errors.
I would like this validation to work with my form. In other forms I just bind an instance of a class to the form and set the binding for each field with validationOnException to true and notifyOnValidationError to true.
I have made the bindings in the create user form as in my other forms, but they do not seem to work. I have tried to set a breakpoint in a set of a property on the NewUser class. It looks like it do not get called/used at all.
This is most likely a simple matter of me missing something, but I can not found out what. Does it have anything to do with the fact that the NewUser class is in my service project and the form is in the client project. I hope you guys can help me.
My code for the NewUser class
public class NewUser
{
private string username;
[Key]
[Required()]
public string UserName { get; set; }
[Key]
[Required()]
[RegularExpression(#"^([\w-\.]+)#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", ErrorMessage="Invalid email. An email must use the format username#mycompany.com")]
public string Email { get; set; }
[Required()]
public string Firstname { get; set; }
[Required()]
public string Lastname { get; set; }
[Required()]
public DateTime Birthsday { get; set; }
[Required()]
public bool SentNewsletter { get; set; }
[Required()]
public bool SentReminders { get; set; }
[Required()]
public string Password { get; set; }
[CustomValidation(typeof(RegistrationValidator), "IsPasswordConfirmed")]
public string ConfirmPassword { get; set; }
[Required()]
public string SecurityQuestion { get; set; }
[Required()]
public string SecurityAnswer { get; set; }
}
My create user form xaml
<navigation:Page x:Class="OenskePortalen.Views.Pages.CreateNewUser"
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"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:uc="clr-namespace:OenskePortalen.Views.Controls"
d:DesignWidth="640" d:DesignHeight="680"
Title="CreateNewUser Page">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="180"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="160"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<uc:InfoBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" DisplayText="Her kan du oprette dig som bruger på ØnskePortalen" VerticalAlignment="Top"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Brugernavn" VerticalAlignment="Center"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text=":" VerticalAlignment="Center"/>
<TextBox Grid.Row="1" Grid.Column="2" x:Name="txtUsername" Text="{Binding UserName, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" VerticalAlignment="Center" Width="150" Margin="5" HorizontalAlignment="Left" />
<TextBlock Grid.Row="2" Grid.Column="0" Text="Fornavn" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text=":" VerticalAlignment="Center"/>
<TextBox Grid.Row="2" Grid.Column="2" x:Name="txtFirstname" Text="{Binding Firstname, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" VerticalAlignment="Center" Width="150" Margin="5" HorizontalAlignment="Left" />
<TextBlock Grid.Row="3" Grid.Column="0" Text="Efternavn" VerticalAlignment="Center"/>
<TextBlock Grid.Row="3" Grid.Column="1" Text=":" VerticalAlignment="Center"/>
<TextBox Grid.Row="3" Grid.Column="2" x:Name="txtLastname" Text="{Binding Lastname, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" VerticalAlignment="Center" Width="150" Margin="5" HorizontalAlignment="Left" />
<TextBlock Grid.Row="4" Grid.Column="0" Text="Email" VerticalAlignment="Center"/>
<TextBlock Grid.Row="4" Grid.Column="1" Text=":" VerticalAlignment="Center"/>
<TextBox Grid.Row="4" Grid.Column="2" x:Name="txtEmail" Text="{Binding Email, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" VerticalAlignment="Center" Width="150" Margin="5" HorizontalAlignment="Left" />
<TextBlock Grid.Row="5" Grid.Column="0" Text="Adgangskode" VerticalAlignment="Center"/>
<TextBlock Grid.Row="5" Grid.Column="1" Text=":" VerticalAlignment="Center"/>
<PasswordBox Grid.Row="5" Grid.Column="2" x:Name="txtPassword" Password="{Binding Password, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" VerticalAlignment="Center" Width="150" Margin="5" />
<TextBlock Grid.Row="6" Grid.Column="0" Text="Gentag adgangskode" VerticalAlignment="Center"/>
<TextBlock Grid.Row="6" Grid.Column="1" Text=":" VerticalAlignment="Center"/>
<PasswordBox Grid.Row="6" Grid.Column="2" x:Name="txtPasswordRepeat" Password="{Binding PasswordConfirm, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" VerticalAlignment="Center" Width="150" Margin="5" />
<TextBlock Grid.Row="7" Grid.Column="0" Text="Sikkerhedsspørgsmål" VerticalAlignment="Center"/>
<TextBlock Grid.Row="7" Grid.Column="1" Text=":" VerticalAlignment="Center"/>
<TextBox Grid.Row="7" Grid.Column="2" x:Name="txtPasswordQuestion" Text="{Binding SecurityQuestion, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" VerticalAlignment="Center" Width="150" Margin="5" HorizontalAlignment="Left" />
<TextBlock Grid.Row="8" Grid.Column="0" Text="Sikkerhedssvar" VerticalAlignment="Center"/>
<TextBlock Grid.Row="8" Grid.Column="1" Text=":" VerticalAlignment="Center"/>
<TextBox Grid.Row="8" Grid.Column="2" x:Name="txtPasswordAnswer" Text="{Binding SecurityAnswer, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" VerticalAlignment="Center" Width="150" Margin="5" HorizontalAlignment="Left" />
<TextBlock Grid.Row="9" Grid.Column="0" Text="Fødselsdag" VerticalAlignment="Center"/>
<TextBlock Grid.Row="9" Grid.Column="1" Text=":" VerticalAlignment="Center"/>
<sdk:DatePicker Grid.Row="9" Grid.Column="2" x:Name="dpBirthsday" SelectedDate="{Binding Birthsday, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" VerticalAlignment="Center" Width="150" Margin="5" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="10" Grid.Column="0" Text="Nyhedsbrev" VerticalAlignment="Center"/>
<TextBlock Grid.Row="10" Grid.Column="1" Text=":" VerticalAlignment="Center"/>
<CheckBox Grid.Row="10" Grid.Column="2" x:Name="cboxNewsletter" IsChecked="{Binding SentNewsletter, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" VerticalAlignment="Center" Margin="5"/>
<TextBlock Grid.Row="11" Grid.Column="0" Text="Påmindelser om fødselsdage" VerticalAlignment="Center"/>
<TextBlock Grid.Row="11" Grid.Column="1" Text=":" VerticalAlignment="Center" />
<CheckBox Grid.Row="11" Grid.Column="2" x:Name="cboxReminders" IsChecked="{Binding SentReminders, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" VerticalAlignment="Center" Margin="5"/>
<StackPanel Grid.Row="12" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Right" Orientation="Horizontal" >
<Button x:Name="btnCreate" Style="{StaticResource GreenButton}" Background="{StaticResource GreenGradientBrush}" Height="20" Margin="5" Click="btnCreate_Click" Cursor="Hand" >
<TextBlock Text="Opret ny bruger" Style="{StaticResource textStyleBlack}" />
</Button>
<Button x:Name="btnCancel" Style="{StaticResource BlueButton}" Background="{StaticResource BlueGradientBrush}" Height="20" Margin="5" Click="btnCancel_Click" Cursor="Hand" >
<TextBlock Text="Annuller" Style="{StaticResource textStyleBlack}" />
</Button>
</StackPanel>
<input:ValidationSummary Grid.Row="13" Grid.Column="0" Grid.ColumnSpan="3" />
</Grid>
And my create user form code behind
public partial class CreateNewUser : Page
{
private NewUser user;
public CreateNewUser()
{
InitializeComponent();
user = new NewUser();
LayoutRoot.DataContext = user;
dpBirthsday.SelectedDate = DateTime.Now;
cboxNewsletter.IsChecked = true;
cboxReminders.IsChecked = true;
}
private void btnCreate_Click(object sender, RoutedEventArgs e)
{
updateValidation();
if (!Validation.GetHasError(LayoutRoot))
{
RegistrationDomainContext context = new RegistrationDomainContext();
NewUser user = new NewUser();
try
{
user.UserName = txtUsername.Text;
user.Password = txtPassword.Password;
user.Email = txtEmail.Text;
user.ConfirmPassword = txtPassword.Password;
user.SecurityQuestion = txtPasswordQuestion.Text;
user.SecurityAnswer = txtPasswordAnswer.Text;
user.Firstname = txtFirstname.Text;
user.Lastname = txtLastname.Text;
user.Birthsday = dpBirthsday.SelectedDate.GetValueOrDefault(DateTime.Now);
user.SentNewsletter = cboxNewsletter.IsChecked.GetValueOrDefault(true);
user.SentReminders = cboxReminders.IsChecked.GetValueOrDefault(true);
context.NewUsers.Add(user);
context.SubmitChanges(RegisterUser_Completed, null);
}
catch (Exception exc)
{
ErrorWindow w = new ErrorWindow(exc);
w.Show();
}
} // end validation
}
private void RegisterUser_Completed(SubmitOperation so)
{
if (so.HasError)
{
ErrorWindow ew = new ErrorWindow(so.Error);
ew.Show();
so.MarkErrorAsHandled();
}
else
{
LoginParameters lp = new LoginParameters(txtUsername.Text, txtPassword.Password);
}
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
MainPage mp = Application.Current.RootVisual as MainPage;
mp.contentFrame.Navigate(new Uri("/home", UriKind.Relative));
}
private void updateValidation()
{
foreach (var current in LayoutRoot.Children)
{
if (current is TextBox)
(current as TextBox).GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (current is PasswordBox)
(current as PasswordBox).GetBindingExpression(PasswordBox.PasswordProperty).UpdateSource();
}
}
}
I believe that you can't databind to a private field - try changing user in your code-behind to a public property (and maybe look at implementing INotifyPropertyChanged).