i've written a tool that generates sql queries using GUI, i want to rewrite the tool using MVVM and WPF, every sql column type has a different control as you can see in the following image
i add a column filter control based on the sql column type, and i generate the controls using code, just like i used to do in windows forms.
While the Model View View Model (MVVM) pattern provides a number of advantages (separation of concerns and ease of testing) to XAML based applications (WPF, Silverlight and Windows RT) . There are number of frustrations in getting things to work - especially in the amount of code that must be generated to do simple things.
Please Sign up or sign in to vote. While the Model View View Model (MVVM) pattern provides a number of advantages (separation of concerns and ease of testing) to XAML based applications (WPF, Silverlight and Windows RT) .
This approach is called Viewmodel First and I think it's the easiest way to do MVVM. Show activity on this post. One option is that you can create TextBoxes and comboboxes in backend by creating a new instanse.
Guess I know how to achieve that, but it is very complex stuff. First you should comprehend MVVM basic concepts.
Main ViewModel should be a class with ObservableCollection
of ViewModels, each of them represents a column with its data and properties.
interface IViewModel : INotifyPropertyChanged,IDisposable
{
}
interface IColumnViewModel : IViewModel
{
}
class ViewModelBase : IViewModel
{
// ... MVVM basics, PropertyChanged etc. ...
}
class MainViewModel : ViewModelBase
{
ObservableCollection<IColumnViewModel> Columns {get; set}
}
In View I suppose something like ItemsControl
with ItemTemplate
, that should embed ContentControl
with DataTemplate
, that shall be automatically selected by WPF according to binded DataContext
of list item. StackPanel
itself is not suitable for that, but it can be invoked as ItemsPanelTemplate
<Window
xmlns:v="clr-namespace:WpfApplication.Views"
xmlns:vm="clr-namespace:WpfApplication.ViewModels">
<Window.Resources>
<DataTemplate DataType="{x:Type TypeName=vm:TextColumnViewModel}">
<v:TextColumnView/>
</DataTemplate>
</Window.Resources>
<ItemsControl
ItemsSource="{Binding Columns}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Window>
So, you should build View/ViewModel pair for every column type.
Hope, my example will help. Good luck with your girlfriend and MVVM :)
If I've understood your scenario correctly : You can use Data Templates & Items Templates For example I've written an application which loads Data into Collection and then shows each item of that collection in a Wrap Panel [ Or stack panel ] based on defined data template. And Wrap penel items are in sync by the collection itself within two way binding You should consider using Observable Collections to achieve this goal Then you can fill the collection and see the results on a view I hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With