|
Why remove the SelectedJob property? The tree in JobListView has it's selecteditem bound to it. How would the VM know a job was selected??
This is hard to discuss without posting tons of code.
If it's not broken, fix it until it is
|
|
|
|
|
Slap my head sideways. This is what happens when I post after 3 hours sleep. With a DP, you provide a static Set... And Get... For the static reference.
|
|
|
|
|
I might be missing something, but from what I can see:
- The
TreeViewEx 's SelectedItem is bound to the SelectedJob property on the JobListViewModel ; - The
JobListView 's SelectedJob is bound to the SelectJobWindowViewModel 's SelectedJob property; - The
JobListViewModel 's SelectedJob is not connected in any way to the JobListView 's SelectedJob ;
I think you need to connect the two SelectedJob properties. Something like this should work:
public JobListView()
{
InitializeComponent();
var binding = new Binding("DataContext.SelectedJob") { Source = this };
SetBinding(SelectedJobProperty, binding);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Please don't set data bindings via code . You get a slap on the wrist for that.
|
|
|
|
|
Hi everybody,
I live in Côte d'Ivoire (West Africa)we're (me and my friend) going to start a project in WPF concerning a drug store. But we have never programed with WPF. So we need someone to coach us.
Please help.
|
|
|
|
|
There are many excellent articles here on Code Project that will take you through the processes of creating WPF apps. Have a look at articles by Sacha Barber and Josh Smith. There's also a free ebook here[^] that teaches you how to use WPF.
|
|
|
|
|
Thanks for your reply but the file no longer exists.
|
|
|
|
|
It does. It's the internal site redirection that causes the problem. Once you've registered, just copy this[^] into your address bar and you get the download page.
|
|
|
|
|
MSDN provides a number of good material for beginners on WPF as well.
|
|
|
|
|
Hi,
I want to create virtual classroom using silverlight and implement it in my asp.net web application. I found a project named silverdraw but it is not running well. I want to create it step by step. Plese help me ASAP..
Thanks in advance
modified 4-Sep-13 7:29am.
|
|
|
|
|
|
Member 10183457 wrote: I want to create it step by step
That's good. Step by step is definitely the way to code it.
Member 10183457 wrote: Plese help me ASAP
Okay. You start off by defining what your requirements are. I cannot stress enough how important this step is. Too many people think that they should just rush in and start coding and that they don't need to do the analysis phase - this is just plain wrong. Once you have figured out what your requirements are, that's when you can start to design your application. Factor in things such as how many people you expect to use the application. The number of concurrent users. How much is being saved out to database. What bandwidth you have available to you.
|
|
|
|
|
I'm working on a WPF application that has some parts that will be run on a Windows 8 Tablet. In this app is a treeview. Clicking the nodes with the mouse works fine. But touch does not. I get no response. Buttons, lists, combos, and other controls all respond. But the treeview does not.
Any ideas?
If it's not broken, fix it until it is
|
|
|
|
|
On the TreeView , set the property IsManipulationEnabled to true.
|
|
|
|
|
Ok, it sort of works. Here's my HierarchicalDataTemplate:
<Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
<Style.Triggers>
<Trigger Property="IsMouseCaptureWithin" Value="True">
<Setter Property="IsSelected" Value="True" />
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsSelected" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
<HierarchicalDataTemplate DataType="{x:Type models:JobSummaryModel}"
ItemsSource="{Binding Path=Nodes}">
<Grid Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Image Source="/FMG.UI.WPF.Shared;component/Media/Images/job_72.png"
Grid.Column="0"
Height="16"
Width="16"
Margin="0,0,3,0"/>
<TextBlock Grid.Column="1"
Text="{Binding Caption}"
IsManipulationEnabled="True"/>
</Grid>
</HierarchicalDataTemplate>
and then my TreeView:
<controls:TreeViewEx BorderThickness="0"
ItemsSource="{Binding Nodes}"
SelectedItemEx="{Binding SelectedTreeNode, Mode=TwoWay}"
IsManipulationEnabled ="True">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
</Style>
</TreeView.ItemContainerStyle>
</controls:TreeViewEx>
The tree is one to many, meaning each parent can have one or more children. Sometimes when I click a parent node it is selected. The VM sets the IsExpanded to true if a parent node is selected.
But I have to touch all over the node area many times to actually get it to select. And sometimes it never does.
If it's not broken, fix it until it is
|
|
|
|
|
Hello Everyone
I have created a small project in WPF. In this project I have a window with Menu Bar such as:
Administration, Explorers, Reports. Each of these menus have sub menus: for instance under Administration Menu-Bar there is a sub-menu called Users, and under Explorers Menu-Bar there is a sub-menu called Menu Categories.
My problem to my question is that on any of the sub-menus I click, it creates a dynamic tabitem and places them in the main tabcontrol (which this is fine), but if i click again on the same sub menus it repeats the same tabitems.
Can someone please help me solve this problem.
the source code for BackOfficeWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using iPosCloud.com.iposcloud.config.uiC_;
using iPosCloud.com.iposcloud.bo.uiC_.explorer;
using iPosCloud.com.iposcloud.bo.uiC_.explorer.ViewModel;
namespace iPosCloud.com.iposcloud.bo.uiC_
{
public partial class BackOfficeWindow : Window
{
private VMBackOfficeWindow vmBackOfficeWindow;
public BackOfficeWindow()
{
InitializeComponent();
vmBackOfficeWindow = new VMBackOfficeWindow();
this.DataContext = vmBackOfficeWindow;
ObservableCollectionTabItems = new ObservableCollection<VMParentForViews>();
}
public ObservableCollection<VMParentForViews> ObservableCollectionTabItems { get; set; }
private void menuItemAdminConfiguration_Click(object sender, RoutedEventArgs e)
{
RestaurantConfigurationView rcv = new RestaurantConfigurationView();
rcv.ShowDialog();
}
#region "Close TabItems"
private void menuItem1_Click(object sender, RoutedEventArgs e)
{
vmBackOfficeWindow.CloseTabItem(sender);
menuUsers.IsEnabled = true;
menuCategories.IsEnabled = true;
}
#endregion
private void menuUsers_Click(object sender, RoutedEventArgs e)
{
this.vmBackOfficeWindow.AddTab("Users");
menuUsers.IsEnabled = false;
}
private void menuCategories_Click(object sender, RoutedEventArgs e)
{
this.vmBackOfficeWindow.AddTab("Category Explorer");
menuCategories.IsEnabled = false;
}
}
}
and the source code for VMBackOfficeWindow.cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Data;
using System.Windows.Controls;
namespace iPosCloud.com.iposcloud.bo.uiC_.explorer.ViewModel
{
public class VMBackOfficeWindow
{
private VMParentForViews vmParentForViews;
public VMBackOfficeWindow()
{
ObservableCollectionTabItems = new ObservableCollection<VMParentForViews>();
}
public ObservableCollection<VMParentForViews> ObservableCollectionTabItems { get; set; }
public void AddTab(string viewType)
{
if(viewType.Equals("Users"))
{
vmParentForViews = new VMUserExplorer();
this.ObservableCollectionTabItems.Add(vmParentForViews);
}
if(viewType.Equals("Category Explorer"))
{
vmParentForViews = new VMCategoryExplorer();
this.ObservableCollectionTabItems.Add(vmParentForViews);
}
ICollectionView collectionView1 = CollectionViewSource.GetDefaultView(this.ObservableCollectionTabItems);
if (collectionView1 != null)
{
collectionView1.MoveCurrentTo(vmParentForViews);
}
}
#region "Close TabItems"
public void CloseTabItem(Object sender)
{
VMParentForViews vmParentForViews = (sender as MenuItem).DataContext as VMParentForViews;
this.ObservableCollectionTabItems.Remove(vmParentForViews);
}
#endregion
}
}
kind regards
roni
|
|
|
|
|
In the code where you are attempting to add the tab, simply check to see if a tab of this name already exists before you add it.
|
|
|
|
|
Hello Pete
Thanks for replying to my question. According to your answer, there isn't any tab-item with the same name, those tab-items are created at run-time.
here is the xaml code of the BackOfficeWindow.xaml
<Window x:Class="iPosCloud.com.iposcloud.bo.uiC_.BackOfficeWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:iPosCloud"
xmlns:vm="clr-namespace:iPosCloud.com.iposcloud.bo.uiC_.explorer.ViewModel"
xmlns:explorer ="clr-namespace:iPosCloud.com.iposcloud.bo.uiC_.explorer"
Title="CLOUD iPOS - Back Office Window" Height="700" Width="1000" WindowStartupLocation="CenterScreen"
xmlns:Intersoft="http://intersoft.clientui.com/schemas"
xmlns:my1="clr-namespace:Intersoft.Client.UI.Controls;assembly=Intersoft.Client.UI.Controls"
xmlns:my2="http://schehttp://schemas.microsoft.com/surface/2008"
xmlns:my="http://schemas.microsoft.com/surface/2008" Foreground="{x:Null}" ShowInTaskbar="False" WindowStyle="ThreeDBorderWindow">
<Window.Resources>
<DataTemplate DataType="{x:Type vm:VMUserExplorer}">
<explorer:UserExplorer />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:VMCategoryExplorer}">
<explorer:CategoryExplorer />
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.BitmapEffect>
<DropShadowBitmapEffect Color="Black" Direction="360" ShadowDepth="10" Opacity=".5" Softness="9" />
</Grid.BitmapEffect>
<Rectangle>
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.508,1.717" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="1"/>
<GradientStop Color="#FFA3A3A3"/>
<GradientStop Color="#FF3C3C3E" Offset="0.582"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Menu Height="30" HorizontalAlignment="Stretch" Margin="2" VerticalAlignment="Top" Width="Auto">
<MenuItem FontFamily="Verdana" Header="Administration" Padding="7,6,8,3" VerticalContentAlignment="Center" Height="30">
<MenuItem Header="Configuration" Name="menuItemAdminConfiguration" Click="menuItemAdminConfiguration_Click" />
<MenuItem Header="Users" Name="menuUsers" Click="menuUsers_Click" />
</MenuItem>
<MenuItem FontFamily="Verdana" Header="Explorers" Padding="7,6,8,3" VerticalContentAlignment="Center" Height="30">
<MenuItem Header="Menu Categories" Name="menuCategories" Click="menuCategories_Click" />
</MenuItem>
<MenuItem FontFamily="Verdana" Header="Reports" Padding="7,6,8,3" VerticalContentAlignment="Center" Height="30">
</MenuItem>
</Menu>
<Grid Name="Master" Margin="4,40,4,4">
<TabControl Name="MasterTabControl" Margin="2" Background="{x:Null}" BorderThickness="2" BorderBrush="#FF3C3C3E" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding ObservableCollectionTabItems}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Header}" >
<TextBlock.ContextMenu>
<ContextMenu Name="contextMenu1">
<MenuItem Header="Close" Name="menuItem1" Click="menuItem1_Click">
</MenuItem>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
</Grid>
</Grid>
<Window.Background>
<ImageBrush ImageSource="/iPosCloud;component/images/HoneyComb.png" Stretch="Fill" TileMode="Tile" Viewport="0,0,46,25" ViewportUnits="Absolute" />
</Window.Background>
</Window>
kin regards
roni
|
|
|
|
|
The tabs are there - all you need to do is search through your ObservableCollection of tabs and see if there's one of the type you want to create. That's what I was alluding to. A naive implementation would be something like this:
if (viewType == "Users")
{
foreach (var tab in ObservableCollectionTabItems)
{
if (tab is VMUserExplorer)
return;
}
} You could simplify this somewhat so that your AddTab and constructor looks like this :
private Dictionary<string, VMParentForViews> viewsDictionary = new Dictionary<string, VMParentForViews>();
public VMBackOfficeWindow()
{
ObservableCollectionTabItems = new ObservableCollection<VMParentForViews>();
viewsDictionary.Add("Users", new VMUserExplorer());
viewsDictionary.Add("Category Explorer", new VMCategoryExplorer());
}
public void AddTab(string viewType)
{
VMParentForViews vm = viewsDictionary[viewType];
Type vmType = vm.GetType();
foreach (var tab in ObservableCollectionTabItems)
{
if (tab.GetType() == vmType)
return;
}
ObservableCollectionTabItems.Add(vm);
} Again, it's still a relatively naive solution, and relies an awful lot on things like string matching and the likes, but it should serve to suffice. If I were doing this, I would go for a much more decoupled approach - you have started some of the way towards this, but there's still a long way to go to get it DI and MVVM.
|
|
|
|
|
Thank you very much Pete that solved my problem...
Once again thank you
kind regards
roni
|
|
|
|
|
Not a problem. Glad I can be of service.
|
|
|
|
|
Hello,
Im already a bit familiar with the MVVM pattern, i still have a few question:
1.When i need Model class in addition to the ViewModel class?
2.If i use the Model class how do i connect the Model and the ViewModel(Binding,events), what is the right way?
3.Where to validate the data in the Model or the ViewModel class?
I know that probabaly there isn't one way to go but what are the rules of thumb?
Thanks.
|
|
|
|
|
You *always* have a View, VM and Model. None of the parts are optional.
View - Strictly 100% XAML (in fact, I prefer to delete the code behind entirely to prevent lazy programmers from uglifying the code). Some people will argue this is not a requirement, but IMO, it should be, it keeps the code cleaner. If you need to do something "complex" with a control, it shouldn't be done in the code behind, but rather broken out into a reusable UserControl.
ViewModel - View binds to this class. Someone will now argue: but how do I set the VM since you have deleted the code behind? -- Answer: ViewLocator & DI. DI plays a second part in this class. It is used to inject the model into the constructor. ViewModel just wraps the Model with lazy load style properties and exposes commands that operate on the model, etc.
Model - This is the API / storage layer of your objects. I like to break this out into its own assembly that a single programmer is managing for consistency. This is the *only* assembly that should even know what a database is. No database / persistence code of any kind is allowed anywhere else in the project. I like breaking the model out into its own assembly to keep things clean and in one place. Model should implement INPC and INCC.
|
|
|
|
|
Collin Jasnoch wrote: 10 min ago
Nice. I usually find the answer about 10 seconds after I click "Submit" on my question
|
|
|
|
|
I have a Silverlight app that displays a map with Deep Zoom. Having just updated the map image, I uploaded the new image files and XAP to our server and even though the XAP refreshes in the browser to the new version (I'm using versioning specifically to force the XAP refresh and that part works fine), the image files for the map, which are stored on the server in the ClientBin, are NOT refreshing automatically in the browser. I eventually got them to refresh for me after failed attempts at refreshing the browser screen, clearing the browser cache (Firefox and IE), and eventually I went into the Windows Control Panel, chose Internet options, and cleared the temporary Internet files from there and only THEN did the map images refresh and I could view the updated map image in my Silverlight app. Did not have to go through all of this with the local development server in VS of course.
So what can I do to force a refresh for everyone who accesses my ASP.NET page with my Silverlight Deep Zoom map on it so that they can see the updated map image and not the old image files being stored locally in their temporary Internet files cache?
Thanks in advance...
--Will
|
|
|
|