开发者

Using IValueConverter to convert binded text to an image

I have a grid where I want to take the text from that cell, convert it to an image and send it back to the grid.

Here is my template code:

<DataTemplate x:Key="categoryCellTemplate">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            &l开发者_如何学Ct;RowDefinition Height="50" />
        </Grid.RowDefinitions>

        <Image Grid.Column="0"
               Margin="1,1,4,1"
               VerticalAlignment="Center"
               Source="{Binding Converter={StaticResource catConverter}}"
               />
    </Grid>
</DataTemplate>

and here is my xaml code:

<Grid>
    <xcdg:DataGridControl Height="311" 
                          HorizontalAlignment="Left" 
                          Name="dataGridControl1" 
                          VerticalAlignment="Top" 
                          Width="503"
                          ItemsSource="{Binding Source={StaticResource Clients}}">
        <xcdg:DataGridControl.Columns>
            <xcdg:Column FieldName="Name" />
            <xcdg:Column FieldName="Age" />
            <xcdg:Column FieldName="Category" />
            <xcdg:Column FieldName="Color"
                         CellContentTemplate="{StaticResource categoryCellTemplate}" />
            <xcdg:Column FieldName="DOB" />
        </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>
</Grid>

where i am having trouble in the template code is to specify what the parameter is.... since he data is bound, I dont know how to send it to the converter class.. please help!!


It depends what kind of parameter you want to pass. You can use the ConverterParamter like this

Source="{Binding Converter={StaticResource catConverter}, ConverterParameter='some parameter'}"

however the ConverterParameter is not a dependency property so you cannot use binding. If you want to supply dynamic context you would need to use multi binding and a multi value converter like this:

<Image.Source>
    <MultiBinding Converter={StaticResource catMultiConverter}>
      <Binding .../>
      <Binding .../>
    </MultiBinding>
</Image.Source>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜