Vincent Dagpin
Vincent Dagpin

Reputation: 3611

Modify result from binding the DataGrid

We need to change the value result from Binding Enums

Example:

public enum Speed
{
   _256kbps,
   _512kbps
}

and we want to bind it to the DataGrid with the result 256kbps without the '-' dash

<sdk:DataGrid SelectedItem="{Binding SelectedBandwidthPlan, Mode=TwoWay}" ItemsSource="{Binding BandwidthPlans}" Margin="10,95,10,33" AutoGenerateColumns="False">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Header="ID" Binding="{Binding BandwidthPlanID}"/>
                <sdk:DataGridTextColumn Header="AccountType" Binding="{Binding AccountType}"/>
                <sdk:DataGridTextColumn Header="BandwidthType" Binding="{Binding BandwidthType}"/>
                <sdk:DataGridTextColumn Header="Description" Binding="{Binding Description}"/>
                <sdk:DataGridTextColumn Header="Speed" Binding="{Binding Speed}"/>
                <sdk:DataGridTextColumn Header="Price" Binding="{Binding Price}"/>
            </sdk:DataGrid.Columns>
            <!--Events for datagrid bound to ViewModel-->
            <!--<i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="{Binding OnFilterExecute}"></i:InvokeCommandAction>
                </i:EventTrigger>
            </i:Interaction.Triggers>-->
        </sdk:DataGrid>

(Is there a way or) How can we modify the output that bound to the datagrid?

Upvotes: 2

Views: 43

Answers (1)

Tyanna
Tyanna

Reputation: 719

To do this, you need to write a converter class that will convert the enum to the user friendly string value.

You first make the converter class in your code behind, then you reference it in your front end markup.

Here is a tutorial that should guide you through it: http://timheuer.com/blog/archive/2008/07/30/format-data-in-silverlight-databinding-valueconverter.aspx

Upvotes: 1

Related Questions