|
PIEBALDconsult is completely right. You need to change MM/dd/yyyy to custom format. Try!
|
|
|
|
|
I HAVE been trying. I can't get it... Which is why I ask what the syntax was.
If it's not broken, fix it until it is
|
|
|
|
|
|
I knocked together a quick sample to test. As long as you're binding to a DateTime field, you can use syntax like this:
<DataGridTextColumn Binding="{Binding CurrentTime, StringFormat='{}{0:ddd, dd MMM}'}" Header="CurrentTime"/>
|
|
|
|
|
Thank you Pete. That did it!
I think I was missing the leading braces.
If it's not broken, fix it until it is
|
|
|
|
|
You're welcome. Yeah, that would cause issues.
|
|
|
|
|
Ya I was pulling some hair out before I finally posted here.
Thanks again
If it's not broken, fix it until it is
|
|
|
|
|
I created a UserControl with an event:
public partial class AssignedEmployeesControl : _BaseUserControl
{
public event RoutedEventHandler AssignmentRemoved;
}
then I add the control to a data grid in the code behind:
private void addAssignedEmployeesColumn()
{
DataGridTemplateColumn employeesColumn = new DataGridTemplateColumn();
employeesColumn.Header = "Assigned Employees";
employeesColumn.Width = new DataGridLength(1, DataGridLengthUnitType.Star); ;
FrameworkElementFactory factory = new FrameworkElementFactory(typeof(AssignedEmployeesControl));
factory.SetValue(AssignedEmployeesControl.EngineRefProperty, EngineRef);
factory.SetValue(AssignedEmployeesControl.AssignmentShiftProperty, new Binding("Shift"));
factory.AddHandler(AssignedEmployeesControl.AssignmentRemoved, new RoutedEventHandler(AssignmentRemoved));
DataTemplate cellTemplate = new DataTemplate();
cellTemplate.VisualTree = factory;
employeesColumn.CellTemplate = cellTemplate;
assignmentsGrid.Columns.Add(employeesColumn);
}
I want to handle the event as follows
private void AssignmentRemoved(object sender, RoutedEventArgs e)
{
}
The AddHandler line doesn't compile. I get
Argument 1: cannot convert from 'System.Windows.RoutedEventHandler' to 'System.Windows.RoutedEvent'
The best overloaded method match for 'System.Windows.FrameworkElementFactory.AddHandler(System.Windows.RoutedEvent, System.Delegate)' has some invalid arguments
The event 'FMG.UI.WPF.Shared.Views.Controls.AssignedEmployeesControl.AssignmentRemoved' can only appear on the left hand side of += or -= (except when used from within the type 'FMG.UI.WPF.Shared.Views.Controls.AssignedEmployeesControl')
I don't understand what's going on here. What's the right way to wire up my event?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
factory.AddHandler(AssignedEmployeesControl.AssignmentRemoved, new RoutedEventHandler(AssignmentRemoved));
Your first parameter should be the event name not the handler; AssignmentRemoved is the name of the handler in your code.
|
|
|
|
|
The name of the event in the control is AssignmentRemoved. I Named the handler the same.
If it's not broken, fix it until it is
|
|
|
|
|
Well the error message says it isn't. Why not change one of the names to make it less confusing and see what happens?
|
|
|
|
|
I posted all the code. You can see the name of the event.
If it's not broken, fix it until it is
|
|
|
|
|
Why doesn't this work? If you zoom in on the image at runtime, you'll notice that the top is red and the bottom is green, but at the transition between them, there is a dark line. It's my understanding that if you use the same offset for two colors, you'll get a hard break.
By my math, 0.611111111111111 * 18 = 11, so its not like I'm giving it half pixels or anything. If I use .5 / .5 for the offsets, I get a hard break.
<Window x:Class="WpfApplication4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Rectangle Height="18">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="Red" />
<GradientStop Offset="0.611111111111111" Color="Red" />
<GradientStop Offset="0.611111111111111" Color="Green" />
<GradientStop Offset="1" Color="Green" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Window>
|
|
|
|
|
Try experimenting with a less accurate number, I have found xaml does not play well beyond 2 decimal palces.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
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.
|
|
|
|