Hi all
Hi have problem with databinding. I can bind data between controlls inside one window, but using same data between multiple windows is trivial.
Here is very simple program, hope you get the idea
Window1.xaml (could be the application MainWindow)
<window x:class="WPF_Template.Window1" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1. Able to be synchronized with window2" Height="145" Width="359">
<grid>
<stackpanel>
<slider name="slider">
Margin="4" Interval="1"
TickFrequency="1"
IsSnapToTickEnabled="True"
Minimum="0" Maximum="100"/>
<stackpanel orientation="Horizontal">
<textblock width="Auto" horizontalalignment="Left">
VerticalAlignment="Center" Margin="4"
Text="Gets and sets the value of the slider:" />
<textbox width="40" horizontalalignment="Center" margin="4">
Text="{Binding
ElementName=slider,
Path=Value,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
</textbox></textblock></stackpanel>
<Button Content="Show Window2" Click="Button_Click"></Button>
</slider></stackpanel>
</grid>
</window>
and Window1.xaml.cs
using System.Windows;
namespace WPF_Template
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Window2 window2 = new Window2();
window2.Show();
}
}
}
Now we have window1 and we want to create window2
<window x:class="WPF_Template.Window2" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2. Always synchronized with window1" Height="126" Width="355">
<grid>
<stackpanel>
<slider name="slider" margin="4" interval="1" tickfrequency="1">
IsSnapToTickEnabled="True"
Minimum="0" Maximum="100"/>
<stackpanel orientation="Horizontal">
<textblock width="Auto" horizontalalignment="Left">
VerticalAlignment="Center" Margin="4"
Text="Gets and sets the value of the slider:" />
<textbox width="40" horizontalalignment="Center" margin="4">
Text="{Binding ElementName=slider,Path=Value,Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
</textbox></textblock></stackpanel>
<Button Content="Close" Click="Button_Click"></Button>
</slider></stackpanel>
</grid>
</window>
and and Window2.xaml.cs
using System.Windows;
namespace WPF_Template
{
public partial class Window2 : Window
{
public Window2()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
So the thing what I want to do is that Window1 and window2 are
synchronized with each other. If you compile my code you will see that data is tied within windows individually and there is no interaction between windows.
Please give me advice!
Best recards
Damn, cannot post my full xaml- code. Hope you got idea anyway :doh: