Jump to content

  • Log In with Google      Sign In   
  • Create Account

WPF : Separation of UI from Data


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 maya18222   Members   -  Reputation: 191

Like
0Likes
Like

Posted 23 September 2012 - 03:42 PM

If you were to use Datatemplates to separate UI from data, such as the following -

namespace WpfApplication1
{
    partial class Data
    {
	    public string SomeData { get; set; }
    }
    public partial class MainWindow : Window
    {
	    public MainWindow()
	    {
		    InitializeComponent();
		    Data d = new Data();
		    d.SomeData = "SomeValue";
		    Content = d;
	    }
    }
}
//===============================
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
				    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
				    xmlns:local="clr-namespace:WpfApplication1"
				    x:Class="WpfApplication1.Data">
    <DataTemplate DataType="{x:Type local:Data}">
	    <Button Content="{Binding Path=SomeData}"/>
    </DataTemplate>
</ResourceDictionary>

How would you then handle events on that Data template? Say for example I wanted to perform some task on the SomeData property in response to the button being clicked.

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS