|
I don't think I explained it well enough, what you've got works fine so to speak, if you set the Grid.Row and Grid.Column of the TextBlocks (in this instance) explicitly then it does arrange them in the appropriate "cell". However if you try and set them through binding then it doesn't work.
E.g.
<TextBlock Grid.Row="{Binding Path=Start,Converter={StaticResource DateToRowConverter}}"
Grid.Col="{Binding Path=Start,Converter={StaticResource DateToColConverter}}" Text="{Binding Path=Summary}" /> Where DateToRowConverter returns say the hour of the event and the DateToColConverter returns the day of week.
(Sorry hit the wrong key so you won't get the full post).
|
|
|
|
|
Sorry - I get it now (to quote American teens, "My bad"). OK - this is a more complicated issue and one that I can't see off the top of my head how you'd accomplish this. Potentially you could do this by setting the Grid.Row and Grid.Column in the converters.
|
|
|
|
|
Pete O'Hanlon wrote: Potentially you could do this by setting the Grid.Row and Grid.Column in the converters.
Hadn't thought of it that way. Any idea why it doesn't work with a "normal" binding expression? Perhaps it's time to dig out Reflector...
|
|
|
|
|
The problem that you have is that you are returning the wrong type of value here. I've just been playing around with a sample of this, and here's a converter sample that you might want to take a look at:
[ValueConversion(typeof(DateTime), typeof(int))]
public class ColDateFormatter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
DateTime startDate = DateTime.Today;
TimeSpan off = startDate.Subtract(DateTime.Parse(value as string));
return off.Days + 1;
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
} Here's a sample of the XAML that you'll need:
<TextBlock Grid.Row="0" Padding="2"
Grid.Column="{Binding XPath=Start, Converter={StaticResource ColDateFormatter}}"
Text="{Binding Mode=OneWay, XPath=Start, Converter={StaticResource Formatter}, ConverterParameter='dd-MMM-yy'}"/> Obviously, you'll need to have added an appropriate number of RowDefinition and ColumnDefinition items. Hmmm. I'm almost tempted to turn this into an article.
|
|
|
|
|
Pete O'Hanlon wrote: The problem that you have is that you are returning the wrong type of value here
My converter was constructed as such:
public class DateToRowConverter : IValueConverter
{
public object ConvertTo(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((DateTime)value).Hour - 8;
}
} I didn't have those attributes so perhaps that was what was missing.
I'll see if I can get a sample project made up for you to illustrate the point...
|
|
|
|
|
And do you have enough RowDefinition and ColumnDefinition items in the XAML? This is important.
|
|
|
|
|
Yep. Check out a quick project I've put together here[^].
[edit]
Seems I can't add TextBlocks for rows and column headers either if I'm using it as an ItemsPanel. Makes sense, perhaps I need to do something with the ItemsPresenter?
[/edit]
|
|
|
|
|
Sorted it out, Thanks to someone on the WPF forum @ MSDN (god I miss the CP forums compared to those). Basically everything I was doing was correct but didn't realise that the TextBlock / ItemTemplate is bound by a ListItem so you have to set the Grid.Row and Grid.Column from there. E.g.
<Style TargetType="{x:Type ListItem}">
<Setter PropertyName="Grid.Row" Value="{Binding Path=Start, Converter={StaticResource DateToRowConverter}}" />
<Setter PropertyName="Grid.Column" Value="{Binding Path=Start, Converter={StaticResource DateToColConverter}}" />
</Style>
|
|
|
|
|
I should have realised that. Stoopid stoopid me.
|
|
|
|
|
Ah well we all learn something (me particularly). You can see a screenshot of the "finished" WpfCalendar[^] and the corresponding outlook[^] calendars.
|
|
|
|
|
|
Why thank you, pretty chuffed so far considering my design skills are non-existant... Now trying to sort out some issues with saving it to a bitmap.
|
|
|
|
|
Hi All,
I am able to add column into a gridview as follows:
<ListView Name="listView1"
ItemsSource="{Binding}" Margin="11,26,115,44">
<ListView.View >
<GridView >
<GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}" />
<GridViewColumn Header="Span Length" DisplayMemberBinding="{Binding Span Length}" />
</GridView>
</ListView.View>
</ListView >
but i want to add multiple column into a single column in the abovew grid view i mean that, i have create some groups to show data into single gridview.
can anybody help me how it is possible because i am new with xaml...
Thanks
Bankey
|
|
|
|
|
Do you mean you want to show multiple bound items in a GridViewColumn? If so, you can bind multiple items into a data template like this:
<DataTemplate>
<TextBlock>
<TextBlock Text="{Binding Path=...}" />
<TextBlock Text="{Binding Path=...}" />
</TextBlock>
</DataTemplate>
|
|
|
|
|
Here are two other ways you can do this.
1. Use a MultiValue Converter that concatenates the two strings and places the output in one TextBlock. I demonstrate this techniques in my article: http://www.codeproject.com/KB/WPF/WPFBusinessAppsPartThree.aspx[^]. This article also has the required value converter code and xaml usage.
Look at the below xaml. See how the MultiBinding Converter syntax works, it takes muliple string values and binding them to one property. MultiBinding converters are a great WPF feature.
<Core_WPF:FormNotification WatermarkMessage="New Record"
Height="28" Panel.ZIndex="99" AutoCollapseTimeout="2">
<Core_WPF:FormNotification.ErrorMessage>
<MultiBinding Converter="{StaticResource formNotificationErrorMessageConverter}">
<Binding Path="Error" />
<Binding Path="ValidationExceptionErrors" ElementName="ucPartThree" />
</MultiBinding>
</Core_WPF:FormNotification.ErrorMessage>
</Core_WPF:FormNotification>
2. In addition to Pete's code of placing the two TextBlocks inside another TextBlock, you could also use a StackPanel as a container for the two TextBlocks.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Karl - that's the thing I really love about WPF. So many ways to solve the same problem, all of them flexible.
|
|
|
|
|
Pete O'Hanlon wrote: the thing I really love about WPF. So many ways to solve the same problem
Me too!
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi,
I'm looking for a way to flip an Image Object horizontally and vertically in C#/WPF.
I couldn't find anything on the web. Hope someone can help me.
Thanks,
Kevin
modified on Wednesday, May 14, 2008 4:07 AM
|
|
|
|
|
In order to flip an image, you need to use the ScaleTransform. For instance:
<ScaleTransform ScaleX="1" ScaleY="-1"> This flips over the Y.
|
|
|
|
|
Wow thanks.
I've been searching for over an hour. And now I've got it in less then 10 minutes.
Thank you for your help.
|
|
|
|
|
No problem. Glad to help.
|
|
|
|
|
Kevin,
Have you downloaded Express Blend yet? If not, currently the March 2008 Preview is free.
The is a SUPER GUI WPF tool that can help you accomplish tasks by setting properties and learn WPF at the same time by studying the XAML code.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Karl Shifflett wrote: Have you downloaded Express Blend yet?
Full version completely free for me - Google "Microsoft Dreamspark". I know it's a clever marketing ploy but you gotta love them for it. Currently installing Server 2003 onto a spare hard-drive ready for return to Uni in three weeks (planning to leave the desktop here at home now I've got a new laptop).
|
|
|
|
|
Ed,
Blend has been free since it came out, because they keep releasing new beta and preview versions.
At some point, a purchase will be required unless you have an MSDN subscription, etc.
Super product!
modified 27-Feb-21 21:01pm.
|
|
|
|
|
I realise that it's been free with respects to the betas but if people want a "stable" version then I thought it wasn't?
Sorry just wanted to shout out about the DreamSpark project because it's so great
|
|
|
|