문제

I think my question is selfexplanatory but to elaborate a little bit here is the case.

I want to assign value to Brush property at runtime. I am assigning it VisualBrush whose key I get from db by

Application.Current.FindResource("Key_Passed_from_DB");

However I have been asked to populate it from string in case that key is not available in application

for e.g. from db i will be passed

<Grid><Path Data="M404....">........</Grid>

Can this be converted to VisualBrush and assigned to my Brush property?

도움이 되었습니까?

해결책

You can Parse Xaml strings into elements as long as you have the required namespaces (or add them before parsing).

Then you can apply your parsed WPF element to a VisualBrush

Working Example:

string elementString = "<Grid xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" >  <Button /> </Grid>";

Visual result = XamlReader.Parse(elementString) as Visual;

VisualBrush myBrush = new VisualBrush(result);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top