Hello!
Please see below image for reference:
Messed up window — ImgBB[
^]
This is my WPF window; "LicenseHolderProfileWindow".
Something fishy is going on when I'm trying to bind the TextBoxes.
I made a phony profile, to show you what's happening. For the first seven TextBoxes, the binding works perfectly. But for the four last, it gets messed up.
- 'Kontonr.:'-textbox gets the value from 'Tlf.:'.
- 'Kontakt:'-textbox is left empty.
- 'Tlf.:'-textbox gets the value from 'E-post:'.
- ...and 'E-post:'-textbox gets the value from 'Kontakt:'.
I checked the
XAML
, and I can't see anything out of the ordinary for any of the TextBoxes. They look like this. No typos. Nothing.:
<TextBox
Name="txtKontakt"
Canvas.Left="464"
Canvas.Top="164"
Width="180"
Height="24"
VerticalContentAlignment="Center"
IsReadOnly="True"
Text="{Binding Kontakt, Mode=TwoWay}"
FontSize="14" />
...and I've set the
DataContext
as such:
d:DataContext="{d:DesignInstance Type=viewmodel:RidelHubMainViewModel}"
Complete XAML files for both parent-window and child-window, as requested
LicenseHoldersWindow (parent-window)
<Window
x:Class="Ridel.Hub.LicenseHoldersWindow"
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:Ridel.Hub"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewmodel="clr-namespace:Ridel.Hub.ViewModel"
Title=""
Width="800"
Height="800"
MaxWidth="800"
MaxHeight="800"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
d:DataContext="{d:DesignInstance Type=viewmodel:RidelHubMainViewModel}"
Background="#f7f7f7"
FontSize="48"
ResizeMode="NoResize"
ShowInTaskbar="False"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<Window.Resources>
<viewmodel:RidelHubMainViewModel x:Key="ViewModelAsDataSource" />
<Style x:Key="FocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle
Margin="2"
SnapsToDevicePixels="true"
Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
StrokeDashArray="1 2"
StrokeThickness="1" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CenterGridHeaderStyle" TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
<SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD" />
<SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070" />
<SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD" />
<SolidColorBrush x:Key="Button.MouseOver.Border" Color="#FF3C7FB1" />
<SolidColorBrush x:Key="Button.Pressed.Background" Color="#FFC4E5F6" />
<SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B" />
<SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4" />
<SolidColorBrush x:Key="Button.Disabled.Border" Color="#FFADB2B5" />
<SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383" />
<Style x:Key="ButtonWithOnlyText" TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
<Setter Property="Background" Value="#f7f7f7" />
<Setter Property="BorderBrush" Value="#f7f7f7" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Padding" Value="2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border
x:Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="true">
<ContentPresenter
x:Name="contentPresenter"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Focusable="False"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsDefaulted" Value="true">
<Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#f7f7f7" />
<Setter TargetName="border" Property="BorderBrush" Value="#f7f7f7" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#f7f7f7" />
<Setter TargetName="border" Property="BorderBrush" Value="#f7f7f7" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="border" Property="Background" Value="#f7f7f7" />
<Setter TargetName="border" Property="BorderBrush" Value="#f7f7f7" />
<Setter TargetName="contentPresenter" Property="TextElement.Foreground" Value="#f7f7f7" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Canvas Margin="10,10,10,10">
<Button
x:Name="btnLogOut"
Canvas.Left="547"
Canvas.Top="17"
Width="233"
Height="31"
Margin="0,0,0,20"
Click="btnLogOut_Click"
Content="LoggedInUser"
FontSize="14"
Style="{DynamicResource ButtonWithOnlyText}" />
<Image
Canvas.Left="18"
Canvas.Top="10"
Width="142"
Height="38"
Source="Images/ridelLOGO.png" />
<Button
x:Name="btnProfil"
Canvas.Left="547"
Canvas.Top="160"
Width="187"
Height="41"
Background="#48bb88"
Content="Se profil"
FontSize="22"
Foreground="White"
IsEnabled="False"
Style="{DynamicResource ButtonWithRoundCornersGreen}"
Visibility="Visible" Click="btnProfil_Click" />
<Button
x:Name="btnNy"
Canvas.Left="547"
Canvas.Top="114"
Width="187"
Height="41"
Background="#48bb88"
Click="btnNy_Click"
Content="Ny løyvehaver"
FontSize="22"
Foreground="White"
Style="{DynamicResource ButtonWithRoundCornersGreen}" />
<Button
x:Name="btnSlett"
Canvas.Left="547"
Canvas.Top="674"
Width="187"
Height="41"
Background="#48bb88"
Command="{Binding RemoveLicenseHoldersCommand}"
CommandParameter="{Binding SelectedItem, ElementName=dgLicenseHolder}"
Content="Slett løyvehaver"
FontSize="22"
Foreground="White"
IsEnabled="False"
Style="{DynamicResource ButtonWithRoundCornersGreen}" />
<Label
Canvas.Left="31"
Canvas.Top="114"
Width="505"
HorizontalContentAlignment="Center"
BorderBrush="#FF707070"
BorderThickness="1"
Content="Løyvehavere"
FontSize="22"
FontWeight="Medium"
Foreground="#48bb88" />
<DataGrid
x:Name="dgLicenseHolder"
Canvas.Left="31"
Canvas.Top="158"
Width="505"
Height="557"
AutoGenerateColumns="False"
BorderBrush="#48bb88"
CanUserAddRows="False"
CanUserDeleteRows="False"
FontSize="20"
IsReadOnly="True"
ItemsSource="{Binding LicenseHolders, Mode=OneWay}"
SelectionChanged="dgLicenseHolder_SelectionChanged"
SelectionMode="Single">
<DataGrid.Columns>
<DataGridTextColumn
Binding="{Binding Path='ID'}"
Header="ID"
IsReadOnly="True"
Visibility="Collapsed" />
<DataGridTextColumn
Width="310"
Binding="{Binding Path='Foretaksnavn'}"
Header="Foretaksnavn"
HeaderStyle="{StaticResource CenterGridHeaderStyle}"
IsReadOnly="True"
Visibility="Visible" />
<DataGridTextColumn
Binding="{Binding Path='Foretaksnummer'}"
Header="Foretaksnummer"
IsReadOnly="True"
Visibility="Collapsed" />
<DataGridTextColumn
Binding="{Binding Path='Adresse'}"
Header="Adresse"
IsReadOnly="True"
Visibility="Collapsed" />
<DataGridTextColumn
Binding="{Binding Path='Postnummer'}"
Header="Postnummer"
IsReadOnly="True"
Visibility="Collapsed" />
<DataGridTextColumn
Width="*"
Binding="{Binding Path='Poststed'}"
Header="Poststed"
HeaderStyle="{StaticResource CenterGridHeaderStyle}"
IsReadOnly="True"
Visibility="Visible" />
<DataGridTextColumn
Binding="{Binding Path='BIC'}"
Header="BIC"
IsReadOnly="True"
Visibility="Collapsed" />
<DataGridTextColumn
Binding="{Binding Path='IBAN'}"
Header="IBAN"
IsReadOnly="True"
Visibility="Collapsed" />
<DataGridTextColumn
Binding="{Binding Path='Kontakt'}"
Header="Kontakt"
IsReadOnly="True"
Visibility="Collapsed" />
<DataGridTextColumn
Binding="{Binding Path='Epost'}"
Header="Epost"
IsReadOnly="True"
Visibility="Collapsed" />
<DataGridTextColumn
Binding="{Binding Path='Tlf'}"
Header="Tlf"
IsReadOnly="True"
Visibility="Collapsed" />
<DataGridTextColumn
Binding="{Binding Path='Kontonummer'}"
Header="Kontonummer"
IsReadOnly="True"
Visibility="Collapsed" />
</DataGrid.Columns>
</DataGrid>
</Canvas>
</Window>
LicenseHolderProfileWindow(parent-window)
<Window
x:Class="Ridel.Hub.LicenseHolderProfileWindow"
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:viewmodel="clr-namespace:Ridel.Hub.ViewModel"
Title=""
Width="736"
Height="562"
MaxWidth="800"
MaxHeight="800"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
d:DataContext="{d:DesignInstance Type=viewmodel:RidelHubMainViewModel}"
Background="#f7f7f7"
FontSize="48"
ResizeMode="NoResize"
ShowInTaskbar="False"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<Window.Resources>
<Style x:Key="FocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle
Margin="2"
SnapsToDevicePixels="true"
Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
StrokeDashArray="1 2"
StrokeThickness="1" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD" />
<SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070" />
<SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD" />
<SolidColorBrush x:Key="Button.MouseOver.Border" Color="#FF3C7FB1" />
<SolidColorBrush x:Key="Button.Pressed.Background" Color="#FFC4E5F6" />
<SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B" />
<SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4" />
<SolidColorBrush x:Key="Button.Disabled.Border" Color="#FFADB2B5" />
<SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383" />
<Style x:Key="ButtonWithOnlyText" TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
<Setter Property="Background" Value="#f7f7f7" />
<Setter Property="BorderBrush" Value="#f7f7f7" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Padding" Value="2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border
x:Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="true">
<ContentPresenter
x:Name="contentPresenter"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Focusable="False"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsDefaulted" Value="true">
<Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#f7f7f7" />
<Setter TargetName="border" Property="BorderBrush" Value="#f7f7f7" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#f7f7f7" />
<Setter TargetName="border" Property="BorderBrush" Value="#f7f7f7" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="border" Property="Background" Value="#f7f7f7" />
<Setter TargetName="border" Property="BorderBrush" Value="#f7f7f7" />
<Setter TargetName="contentPresenter" Property="TextElement.Foreground" Value="#f7f7f7" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Canvas Margin="10,10,42,10">
<Button
Name="btnLogOut"
Canvas.Left="522"
Canvas.Top="17"
Width="173"
Height="31"
Margin="0,0,0,20"
Click="btnLogOut_Click"
Content="LoggedInUser"
FontSize="14"
Style="{DynamicResource ButtonWithOnlyText}" />
<Image
Canvas.Left="25"
Canvas.Top="10"
Width="142"
Height="38"
Source="Images/ridelLOGO.png" />
<Label
Canvas.Left="31"
Canvas.Top="97"
Width="639"
HorizontalContentAlignment="Center"
BorderBrush="#FF707070"
BorderThickness="1"
Content="Profil"
FontSize="22"
FontWeight="Medium"
Foreground="#48bb88" />
<Rectangle
Canvas.Left="31"
Canvas.Top="141"
Width="639"
Height="337"
RenderTransformOrigin="0.5,0.5"
Stroke="#48bb88" />
<TextBox
Name="txtID"
Canvas.Left="42"
Canvas.Top="106"
Width="28"
Height="24"
VerticalContentAlignment="Center"
IsReadOnly="True"
Text="{Binding ID, Mode=TwoWay}"
FontSize="14" />
<TextBox
Name="txtKontakt"
Canvas.Left="464"
Canvas.Top="164"
Width="180"
Height="24"
VerticalContentAlignment="Center"
IsReadOnly="True"
Text="{Binding Kontakt, Mode=TwoWay}"
FontSize="14" />
<TextBox
Name="txtTlf"
Canvas.Left="464"
Canvas.Top="200"
Width="180"
Height="24"
VerticalContentAlignment="Center"
IsReadOnly="True"
Text="{Binding Tlf, Mode=TwoWay}"
FontSize="14" />
<TextBox
Name="txtEpost"
Canvas.Left="464"
Canvas.Top="234"
Width="180"
Height="24"
VerticalContentAlignment="Center"
IsReadOnly="True"
Text="{Binding Epost, Mode=TwoWay}"
FontSize="14" />
<TextBox
Name="txtForetaksnavn"
Canvas.Left="150"
Canvas.Top="166"
Width="180"
Height="24"
VerticalContentAlignment="Center"
Text="{Binding Foretaksnavn, Mode=TwoWay}"
IsReadOnly="True"
FontSize="14" />
<TextBox
Name="txtForetaksnr"
Canvas.Left="150"
Canvas.Top="203"
Width="180"
Height="24"
VerticalContentAlignment="Center"
IsReadOnly="True"
Text="{Binding Foretaksnummer, Mode=TwoWay}"
FontSize="14" />
<TextBox
Name="txtAdresse"
Canvas.Left="150"
Canvas.Top="241"
Width="180"
Height="24"
VerticalContentAlignment="Center"
IsReadOnly="True"
Text="{Binding Adresse, Mode=TwoWay}"
FontSize="14" />
<TextBox
Name="txtPoststed"
Canvas.Left="150"
Canvas.Top="279"
Width="180"
Height="25"
VerticalContentAlignment="Center"
IsReadOnly="True"
Text="{Binding Poststed, Mode=TwoWay}"
FontSize="14" />
<TextBox
Name="txtPostnummer"
Canvas.Left="261"
Canvas.Top="317"
Width="71"
Height="24"
VerticalContentAlignment="Center"
IsReadOnly="True"
Text="{Binding Postnummer, Mode=TwoWay}"
FontSize="14" />
<TextBox
Name="txtBIC"
Canvas.Left="152"
Canvas.Top="357"
Width="180"
Height="24"
VerticalContentAlignment="Center"
IsReadOnly="True"
Text="{Binding BIC, Mode=TwoWay}"
FontSize="14" />
<TextBox
Name="txtIBAN"
Canvas.Left="151"
Canvas.Top="393"
Width="180"
Height="24"
VerticalContentAlignment="Center"
IsReadOnly="True"
Text="{Binding IBAN, Mode=TwoWay}"
FontSize="14" />
<TextBox
Name="txtKontonr"
Canvas.Left="150"
Canvas.Top="429"
Width="180"
Height="24"
VerticalContentAlignment="Center"
IsReadOnly="True"
Text="{Binding Kontonummer, Mode=TwoWay}"
FontSize="14" />
<Button
Name="btnLagre"
Canvas.Left="528"
Canvas.Top="423"
Width="116"
Height="30"
HorizontalContentAlignment="Center"
Background="#48bb88"
Command="{Binding RefreshCommand}"
Content="Lagre"
FontSize="16"
Foreground="White"
IsEnabled="false"
Style="{DynamicResource ButtonWithRoundCornersGreen}" Click="btnLagre_Click"/>
<Button
Name="btnSeeDrivers"
Canvas.Left="528"
Canvas.Top="387"
Width="116"
Height="30"
HorizontalContentAlignment="Center"
Background="#48bb88"
Command="{Binding RefreshCommand}"
Content="Sjåfører"
FontSize="16"
Foreground="White"
Style="{DynamicResource ButtonWithRoundCornersGreen}"/>
<Button
Name="btnSeeLicenses"
Canvas.Left="528"
Canvas.Top="351"
Width="116"
Height="30"
HorizontalContentAlignment="Center"
Background="#48bb88"
Command="{Binding RefreshCommand}"
Content="Løyver"
FontSize="16"
Foreground="White"
Style="{DynamicResource ButtonWithRoundCornersGreen}"/>
<Button
Name="btnAllowEdit"
Canvas.Left="512"
Canvas.Top="314"
Width="132"
Height="30"
HorizontalContentAlignment="Center"
Background="#48bb88"
Command="{Binding RefreshCommand}"
Content="Tillat redigering"
FontSize="16"
Foreground="White"
Style="{DynamicResource ButtonWithRoundCornersGreen}" Click="btnAllowEdit_Click"/>
</Canvas>
</Window>
What I have tried:
I've gone through the XAML, looking for discrepancies or irregularities. Found none.
Might be difficult to answer without seeing the rest of my code, but is this a known issue, and are there any obvious things I could do to try to rectify it?
Where could I have messed up?
Thanks!