English 中文(简体)
模板清单箱中具体内容的改变方式如何?
原标题:How change style of specific element in templated listbox?
  • 时间:2011-11-21 17:37:32
  •  标签:
  • c#
  • wpf

我有一个名单箱,定义如下:

<ListBox ... ItemTemplate="{DynamicResource User}"/>

项目2:

<DataTemplate x:Key="User">
            <DataTemplate.Resources>
                <Style TargetType="{x:Type Border}" x:Key="Ordinal">
                    <Setter Property="Background">
                        <Setter.Value>
                            ...
                        </Setter.Value>
                    </Setter>
                </Style>
                <Style TargetType="{x:Type Border}" x:Key="Current">
                    <Setter Property="Background">
                        <Setter.Value>
                            ...
                        </Setter.Value>
                    </Setter>
                </Style>
            </DataTemplate.Resources>
            <Border CornerRadius="5" Padding="5" Margin="0,0,5,0" Style="{StaticResource Ordinal}">
                ...
            </Border>
        </DataTemplate>

Now I have an event handler which should set style of item in provided index to "current":

void SetCurrent(int Index)
{
    ?
}

如何做到这一点?

http://www.un.org。

也许使用项目Control会使这一点更加容易?

问题回答

在此情况下,我将使用以下两种方法:

 <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{StaticResource CurrentBrushKey}" />

以及确定名单箱的选定系统(优于——不使用SetaCurrent()功能,从您的观点来看是逻辑的)

希望将有助于





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签