开发者

Change selected row to bold text Silverlight XAML

I am fairly new to Silverlight development and I am still trying to get my head around MVVM.

I have a data grid which displays a list of results, What I need to have happen, is the text in the row to turn bold on selection.

I have my xaml pages split into structure and style which reference a viewModel.cs page.

I would appr开发者_如何学Pythoneciate any advice or pointers on how to acheive this.

Thank you for your time in looking into my post!

Dave.


you could try something like this :

Xaml :

<sdk:DataGrid AutoGenerateColumns="True" SelectionChanged="dataGrid1_SelectionChanged" ItemsSource="{Binding .}" Name="dataGrid1">     

Code behind :

private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            foreach (DataGridColumn column in this.dataGrid1.Columns)
            {
                FrameworkElement element = column.GetCellContent(e.AddedItems[0]);
                (element as TextBlock).FontWeight = FontWeights.Bold;

                if (e.RemovedItems.Count > 0)
                {
                    element = column.GetCellContent(e.RemovedItems[0]);
                    (element as TextBlock).FontWeight = FontWeights.Normal;
                }

            } 
        }

Hope it helps ;)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜