开发者

programmatically binding images to silverlight grid cell based on condition [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

how can i programmatically binding images to silverlight datagrid cell of a particular column based on the datasource v开发者_JS百科alues


Use an implementation of IValueConverter that I blog about here. I'll assume for the moment (your question lacks detail so I'll make some up) that you have some kind of property that exposes an enum of a finite set of states.

In your case the value converter will contain a ResourceDictionary of BitmapImage entries:-

        <local:StringToObjectConverter x:Key="StatusToIcon">
            <ResourceDictionary>
                <BitmapImage UriSource="/Assets/State1.png" x:Key="State1" />
                <BitmapImage UriSource="/Assets/State2.png" x:Key="State2" />
                <BitmapImage UriSource="/Assets/UnknownState.png" x:Key="__default__" />
            </ResourceDictionary>
        </local:StringToObjectConverter>   

In the template for your cell you would use:-

<Image Source="{Binding State, Converter={StaticResource StatusToIcon}}" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜