About the author

Brian Keating is a developer addicted to Microsoft Technologies.

Month List

RecentComments

Comment RSS

Xaml gotya

clock December 6, 2010 19:51 by author Brian Keating |

Here's one I'm ashamed to admit caught me as I was finishing up work this evening, it's been a good few weeks since I've gone near wpf/silverlight given I was on holidays and spend my time playing with WF4 and MVC2.

Anyway in screenshot below.. vs2010 .net 3.5 sp1 I was binding some data to a datagrid.

 I omitted to remove the offending closing xml comment you can see in the xaml "-->"

And low and behold the binding breaks down without any prior warning,,,, infact my object collection is totally ignored and the "-->" is passed to the binding, I know this because I removed the binding paths in the columns and was presented with "-->" in my grid...

Just an interesting one to keep in mind.. If you're like me, u couldn't switch off the computer this evening until this peculiar behaviour was explained..

 

Maybe it will save you some time if you come accross it.

 




WaitCursor and MVVM

clock June 3, 2010 16:43 by author Brian Keating |

Ever wondered how to display the correct cursor in an application that is databinded to async methods?

Pretty easy solution, just databind the cursor on the window itself.

Here's how:

  • Add an IsBusy property on the DataContext (and implement INotifyPropertyChanged on it)
  • Addt the following to your window xaml

xmlns:valueConverters="clr-namespace:XXX.ValueConverters"
Cursor="{Binding IsBusy, Converter={valueConverters:CursorExtensionConverter}}" 

 

  • Create the following ValueConverter

public class CursorExtensionConverter : MarkupExtension, IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value != null && ((bool)value))
            return Cursors.Wait;           
        else
            return Cursors.Arrow;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        return instance;
    }

    private static CursorExtensionConverter instance = new CursorExtensionConverter();
}

 

Note: Use of MarkupExtension

 

 




WPF ListViewItem Commands with MVVM pattern

clock May 12, 2010 10:44 by author Brian Keating |

If you're interested to see how to attach commands to listview items for use with an implementation of the MVVM pattern, have a look at this.

 

<Style x:Key="Local_OpenEntityStyle"
           TargetType="{x:Type ListViewItem}">
        <Setter Property="acb:CommandBehavior.Event"
                        Value="MouseDoubleClick" />
        <Setter Property="acb:CommandBehavior.Command"
                        Value="{Binding ElementName=uiEntityListDisplay, Path=DataContext.OpenEntityCommand}" />
        <Setter Property="acb:CommandBehavior.CommandParameter"
                        Value="{Binding}" />
</Style>

 

Here the command to be fired on the MouseDoubleClick event is set, the CommandParameter, will be the data object that we click on.




Declarative Ria Data and Controls

clock March 24, 2010 21:27 by author Brian Keating |

I'm really loving this declarative approach with silverlight and wpf... (ask me why and I can't tell you ! :-)

Anyway I've just stumbled across a way of managing RiaDataContexts Declaratively
I found it on the Telerik samples.... If you've not looked at these guys controls then check them out!!

 

<navigation:Page xmlns:dataFormToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"  xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
  x:Class="SiteDocs.Loler"
  xmlns="//schemas.microsoft.com/winfx/2006/xaml/presentation">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:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
  xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
  xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Ria"
  xmlns:e="clr-namespace:SiteDocs.Web.Services"
  xmlns:riaData="clr-namespace:System.Windows.Data;assembly=System.Windows.Controls.Ria"
  mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" 
  Style="{StaticResource PageStyle}"
>

  <Grid x:Name="LayoutRoot" >
    <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}" >

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
    
    <Grid x:Name="gridLolerLeft" >
     <Grid.RowDefinitions>
      <RowDefinition />
      <RowDefinition Height="Auto"/>
     </Grid.RowDefinitions>

                    <riaControls:DomainDataSource x:Name="DomainDataSource1" AutoLoad="True" QueryName="GetLolers" PageSize="10">
                        <riaControls:DomainDataSource.DomainContext>
                            <e:LolerContext />
                        </riaControls:DomainDataSource.DomainContext>
                        <riaControls:DomainDataSource.FilterDescriptors>
                            <riaData:FilterDescriptorCollection LogicalOperator="Or" />
                        </riaControls:DomainDataSource.FilterDescriptors>
                    </riaControls:DomainDataSource>

                    <telerik:RadGridView x:Name="RadGridView1" ItemsSource="{Binding Data, ElementName=DomainDataSource1}"
                             Filtering="RadGridView1_Filtering" IsBusy="{Binding IsBusy, ElementName=DomainDataSource1}" />
           <telerik:RadDataPager x:Name="RadDataPager1" Grid.Row="1" Source="{Binding Data, ElementName=DomainDataSource1}" DisplayMode="FirstLastPreviousNextNumeric, Text" IsTotalItemCountFixed="True"/>

    
    </Grid>

                </Grid>
    </ScrollViewer>
  </Grid>

</navigation:Page>




Popups in wpf

clock March 17, 2010 17:14 by author Brian Keating |

Here is come code to show a popup in wpf, i've nothing in the popup at the moment, just a gradient background and border.

<Popup Name="popup1" 
   Width="{Binding ElementName=bdrCalendar, Path=ActualWidth, Converter={StaticResource MarginValueConverter}}"
   Height="150"
   Placement="Center"
   PopupAnimation="Scroll"
   AllowsTransparency="True"
   PlacementTarget="{Binding ElementName=bdrCalendar}"
   MouseDown="popup1_MouseDown" >
 <ctrls:PopupContent />
</Popup>