|
Hi Guys,
I have a view model with code below.
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace ChurchWX
{
public class ViewModel : INotifyPropertyChanged
{
private ObservableCollection<Group> _groups;
public ObservableCollection<Group> Groups
{
get { return _groups; }
set
{
_groups = value;
OnPropertyChanged("Groups");
}
}
public ViewModel()
{
Groups = GenerateGroups();
}
private ObservableCollection<Group> GenerateGroups()
{
ObservableCollection<Group> groups = new ObservableCollection<Group>();
var mailGroup = new Group() { Title = "Mail",
LargeImagePath = @"/XamOutlookBarDataBinding;component/Images/Mail32.png",
SmallImagePath = @"/XamOutlookBarDataBinding;component/Images/Mail16.png" };
var rootMailItem = new MenuItem() { Title = "Personal Folders", IsExpanded = true };
rootMailItem.Children.Add(new MenuItem() { Title = "Inbox", ImagePath = @"/XamOutlookBarDataBinding;component/Images/InboxFolder16.png" });
rootMailItem.Children.Add(new MenuItem() { Title = "Drafts", ImagePath = @"/XamOutlookBarDataBinding;component/Images/DraftsFolder16.png" });
rootMailItem.Children.Add(new MenuItem() { Title = "Sent Items", ImagePath = @"/XamOutlookBarDataBinding;component/Images/SentFolder16.png" });
rootMailItem.Children.Add(new MenuItem() { Title = "Deleted Items", ImagePath = @"/XamOutlookBarDataBinding;component/Images/DeletedFolder16.png" });
mailGroup.Items.Add(rootMailItem);
var contactsGroup = new Group() { Title = "Contacts",
LargeImagePath = @"/XamOutlookBarDataBinding;component/Images/Contact32.png",
SmallImagePath = @"/XamOutlookBarDataBinding;component/Images/Contact16.png" };
var rootContactItem = new MenuItem() { Title = "My Contacts", IsExpanded = true };
rootContactItem.Children.Add(new MenuItem() { Title = "Suggested Contacts", ImagePath = @"/XamOutlookBarDataBinding;component/Images/Contact16.png" });
rootContactItem.Children.Add(new MenuItem() { Title = "Contacts" , ImagePath = @"/XamOutlookBarDataBinding;component/Images/Contact16.png" });
contactsGroup.Items.Add(rootContactItem);
groups.Add(mailGroup);
groups.Add(contactsGroup);
return groups;
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyname)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyname));
}
}
}
I also have the XAML below to display display the content defined in the viewmodel.
<UserControl xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" x:Class="ChurchWX.MainPage"
xmlns:local="clr-namespace:ChurchWX"
xmlns:D="clr-namespace:ChurchWX.Classes"
xmlns:ig="http://schemas.infragistics.com/xaml"
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:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<UserControl.DataContext>
<local:ViewModel/>
</UserControl.DataContext>
<UserControl.Resources>
<Style TargetType="ig:OutlookBarGroup">
<Setter Property="Header" Value="{Binding Title}"/>
<Setter Property="LargeIconTemplate" Value="{Binding LargeImagePath}"/>
<Setter Property="SmallIconTemplate" Value="{Binding SmallImagePath}"/>
<Setter Property="Content" Value="{Binding Items}" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate >
<ig:XamDataTree ItemsSource="{Binding}">
<ig:XamDataTree.GlobalNodeLayouts>
<ig:NodeLayout Key="ItemsLayout" TargetTypeName="MenuItem" DisplayMemberPath="Title" IsExpandedMemberPath="IsExpanded">
<ig:NodeLayout.CollapsedIconTemplate>
<DataTemplate>
<Image Source="{Binding Data.ImagePath}" />
</DataTemplate>
</ig:NodeLayout.CollapsedIconTemplate>
</ig:NodeLayout>
</ig:XamDataTree.GlobalNodeLayouts>
</ig:XamDataTree>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border x:Name="brTop" Grid.Row="0" BorderBrush="White" BorderThickness="0,0,0,1" Height="30">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0.299"/>
<GradientStop Color="#FFC1C9CD" Offset="0.979"/>
</LinearGradientBrush>
</Border.Background>
<TextBlock Margin="12,0,0,0" Text="Church Works v1.0.0" FontSize="12"
VerticalAlignment="Center" HorizontalAlignment="Left" FontWeight="Bold">
<TextBlock.Effect>
<DropShadowEffect Color="White" BlurRadius="1" ShadowDepth="1"/>
</TextBlock.Effect>
<TextBlock.Foreground>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFB292DA"/>
<GradientStop Color="#FF292929" Offset="1"/>
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>
</Border>
<Grid x:Name="MainPageLayoutRoot" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="60" />
<ColumnDefinition Width="4"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Canvas x:Name="propertyCanvas" Grid.Column="2"></Canvas>
<StackPanel Name="stpOutlookBar" Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="150">
<ig:XamOutlookBar GroupsSource="{Binding Groups}"/>
</StackPanel>
<sdk:GridSplitter Grid.Column="1" HorizontalAlignment="Left" Grid.RowSpan="2" Background="#FFBACBFF"/>
<StackPanel Grid.Column="2" Width="800">
<Grid x:Name="WorkAreaLayoutRoot" Background="White" Grid.Column="2">
</Grid>
</StackPanel>
</Grid>
</Grid>
</UserControl>
the xamOutlookbar only displays ChurchWX.Groups on the two groups defined.
I will be glad is someone will direct me as to where I went wrong.
Thank you
|
|
|
|
|
I'm creating a control that has 3 different views, Day, Week, and Month. Each of those is a UserControl that can only be used inside my master control.
How can I prevent a developer from creating an instance of a Day, Week, or Month control?
If it's not broken, fix it until it is
|
|
|
|
|
I have 3 tables which are linked to each other with Primary and Foreign key relationship. When I use the datasource combinely for all the 3 tables unable to edit the records and Add option is not visible. What should be the resoultion
Mahendra
|
|
|
|
|
I am creating a custom control, and I want to programmatically add it to a datagrid in the last column at runtime.
I've never done anything like this be before. Can someone show me how this is done, or point me in the right direction?
Many thanks!
If it's not broken, fix it until it is
|
|
|
|
|
Hi,
You could try this Tip/Trick to programmatically add a column at runtime.
And about DataGrid Column types you could refer DataGrid on MSDN
good luck!
Josh
|
|
|
|
|
I normally Google for this kind of stuff, but I'm not sure of the proper name / terminology since I'm not really a math guy, so I'm not coming up with any hits...
I'm trying to draw a very simple "graph". 0,0 10,10 20,3 30,15, etc.
So, right now, I just add the points to a PolyLine and all is good.
But this results in a sharp zig-zag line... how do I make it into a "smoother" "wave" type line based on the same point array? The only term I remember from math class is bezier curves lol, but that doesn't seem to be what I'm looking for.
|
|
|
|
|
Try looking for Spline interpolation. Basically you're looking for a continuous function or a set of functions able to interpolate the points and retain continuity.
So yes, splines are the way to go!
|
|
|
|
|
Seems like there are a bunch of different spline types. Am I looking for the cannonical spline?
|
|
|
|
|
Cubic splines are a good balance between continuity and computation speed, but B-splines can be good too.
|
|
|
|
|
Hmm... I found some Petzold code that creates a canonical spline in WPF, seems like its working (doing what I want) unless I don't know what I'm talking about which is entirely possible since I don't know the diffs between all those splines haha. All I know is that it looks like a wave interpertation of my zig-zag line. Thanks!
|
|
|
|
|
I've got a WPF TreeView that is using the structure in Josh Smith's article[^]
In my case I've only got one type of object (Unit) that has a self-referencing hierarchy. So I only have one item ViewModel and so only the one HierarchicalDataTemplate.
Everything 'works', but there are two usability issues:
1) clicking on the expander can take a while, and there's nothing to indicate to the user that its happening.
2) the expanders appear on items that have no children (I assume due to the DummyChild that gets added.
For the 1st issue, I added a INPC property IsLoading to the base item VM TreeViewItemViewModel . Then I've been round and round in circles trying to get this working...at the moment I've got...
In my UnitTreeItemViewModel in the LoadChildren override I set IsLoading before and after.
IsLoading = true;
Thread.Sleep(TimeSpan.FromSeconds(0.75).Milliseconds);
UI.UIDispatcher.Invoke((ThreadStart)delegate()
{
foreach (Unit u in UnitCache.Units.AllUnits.Where(WhereClause))
base.Children.Add(new UnitTreeItemViewModel(u, this, _uh));
});
IsLoading = false;
Finally I added a simple TextBlock that I make visible based on IsLoading :
<TextBlock Text="..."
x:Name="loadingText"
Visibility="{Binding Path=IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}"/>
But all this does is show on the child items (after they appear), not the parent
I've tried changing it to set the Parent's IsLoading, but that didn't seem to work either, the root items don't have Parents for a start...
And now I'm stuck...
I've created a Pastie of the full code here.
|
|
|
|
|
You should post your question in the forum at the end of the article, so Josh can help you.
|
|
|
|
|
I have a wpf window which is a splash screen. I want it to be displayed for a certain time interval (say 5 sec) and then it closes and new login window opens.the problem is that in splash screen there are some process undergoing so if i call sleep() they stop working and mouse pointer shows busy symbol.
|
|
|
|
|
Sleep is a blocking operation. Of course it will show the busy symbol.
The normal way to do this is to load your data on a background thread.
|
|
|
|
|
can you show sample code for that.possibly using System.Timers.Timer?
|
|
|
|
|
Task.Factory.StartNew(()=>{
});
|
|
|
|
|
If I have an xml document of books, like:
<Books>
<Book>
<Title>WPF For The Hard-of-Learning</Title>
<Category>N</Category>
</Book>
</Books>
and an xml document of book categories:
<Categories>
<Category>
<ID>F</ID>
<Name>Fiction</Name>
</Category>
<Category>
<ID>N</ID>
<Name>Non-Fiction</Name>
</Category>
</Categories>
is there a way to bind the element value from the second document that is associated with an element in the first document?
To clarify using the above xml document examples, I'd like to display the book title and its category name (Non-Fiction), not its Category code (N).
In a code-behind file I'd like to load into XmlDocument objects the xml from a file that holds the Books xml and from a file that holds the Categories xml. In the code-behind I would assign the xml documents as the Document property of a couple XmlDataProviders defined in the XAML.
|
|
|
|
|
In your code behind, should be ViewModel, create a class, a Model, with the Book properties and add an additional property for the Category. Insert the records from the Book xml and update the item with the Category details.
This is the normal process of creating a model to match the UI requirements. Your UI will often not match the database structure, that is why there are such concepts as DAL, Mode, View, ViewModel.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi all ,
I need to create add in project in silver-light mvvm project , i'm complete new to create add in projects please help me .i checked in online and i found one project from this site .but it is working for only visual studio . I need to work for my project . please help me ...
Thank you .
|
|
|
|
|
Victor
Visual Studio is and IDE, Integrated Development Environment, your project and the article you found are BOTH built on VS, the article is just another project built by a developer. How you can call yourself a "Senior" developer in your profile baffles me!
Do some research into MEF[^]. However I would suggest you need to do some more basic reading before tackling MEF!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: How you can call yourself a "Senior" developer Means you can use Copy & Paste.
|
|
|
|
|
I think even that may be beyond him from the OP.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello Mycroft Holmes ,
Thank you for your response , yes i was downloaded the sample project and try to understanding how that is implemented (this is not use for me but it will give some idea how to start,so that i downloaded.) Frankly i don't know how to create a add in project. I thought some one will give idea how start while posting this question but, i got different answer. please have any idea help me still if you think this is useless question just ignore this .
Thanks again.
|
|
|
|
|
Why have you sent this to me? I am (obviously) not Mycroft Holmes.
|
|
|
|
|
What do you mean by Add in Silverlight Project? This isn't a combination I've come across before - perhaps you could explain what effect you're expecting.
|
|
|
|