c# - (wpf) Application.Current.Resources vs FindResource -


so, i'm making gui thingy wpf in c#. looks this:

it's not done right now. 2 rows attempt @ making sort of data table, , hard-coded in xaml.

now, implementing add new fruit button functionality in c#. have following style in xaml governs background images of rows should like:

<style x:key="stretchimage" targettype="{x:type image}">     <setter property="verticalalignment" value="stretch"/>     <setter property="horizontalalignment" value="stretch"/>     <setter property="stretch" value="fill"/> </style> 

so, in code, create image each column, col0, col1, , col2, , if use following code,

col0.style = (style)application.current.resources["stretchimage"]; col1.style = (style)application.current.resources["stretchimage"]; col2.style = (style)application.current.resources["stretchimage"]; 

it adds new row looks this:

as can see, it's not quite right... , stretching window exacerbates problem:

it seems not respecting style's "stretch" property.

but then, if instead change style loading code to

col0.style = (style)findresource("stretchimage"); col1.style = (style)findresource("stretchimage"); col2.style = (style)findresource("stretchimage"); 

it works beautifully:

(again, app isn't finished, don't worry that), main question is: what's difference between application.current.resources[] , findresource()? why 1 seem ignore of properties while other doesn't? , how, if @ possible, might application.current.resources[] work properly?

resources can defined on element in visual tree. frameworkelement.findresource() walk tree looking resource @ each node, , make way application. application.current.resources[] skips of , goes straight resources on application. want use findresource() can override styles @ various points.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -