|
The problem seems to be that DrawingBrush has round-off errors internally or it doesn't work the same way as the LinearGradientBrush in terms of origin / relative ratios. Like I said, LinearGradientBrush hits the line consistently with my "math". DrawingBrush isn't even consistent at 50% which should not even be suspectible to round-off errors since its a whole pixel. Sometimes its 1 pixel too high, sometimes its 1 pixel too low. Also tried TransformToVisual to go from the line to the path, but TransformToVisual considers both shapes to be the same height (as the height of the control), so it just maps the points 1 to 1. Tried Math.Round() and Math.Ceiling(), etc. LOL. The line itself certainly doesn't move around, its always at the exact correct location. Tried get the rendered bounds of the path and calculating it from that, but same thing... +/- 1 issues. Also tried setting everything to absolute mode and setting the rectangles identically, nope... Maybe the LinearGradientBrush only *appears* to be working and is hiding the +/- 1 issues with the gradiented color switch.
|
|
|
|
|
I have a DataGrid with a Date column. I need to show the date as:
"Wed, 12 Dec" - Short day, day number, and short month
I've tried a bunch of options, including these[^], but I can't get it to work.
What's the correct XAML for this?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
|
Technically accurate but practically useless.
I didn't ask for the ISO standards.
What's the XAML?? I tried a bunch and it won't compile.
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: I tried a bunch and it won't compile. Interesting, but you cannot expect people to guess what that bunch comprises.
|
|
|
|
|
Which is exactly why I provided the link to what I tried
If it's not broken, fix it until it is
|
|
|
|
|
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
|
|
|
|