XamlIlTests.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Runtime.CompilerServices;
  7. using Avalonia.Controls;
  8. using Avalonia.Data.Converters;
  9. using Avalonia.Data.Core;
  10. using Avalonia.Input;
  11. using Avalonia.Interactivity;
  12. using Avalonia.Markup.Xaml.UnitTests.Xaml;
  13. using Avalonia.Media;
  14. using Avalonia.Styling;
  15. using Avalonia.Threading;
  16. using Avalonia.UnitTests;
  17. using Avalonia.VisualTree;
  18. using Xunit;
  19. namespace Avalonia.Markup.Xaml.UnitTests
  20. {
  21. public class XamlIlTests : XamlTestBase
  22. {
  23. [Fact]
  24. public void Transitions_Should_Be_Properly_Parsed()
  25. {
  26. var parsed = (Grid)AvaloniaRuntimeXamlLoader.Parse(@"
  27. <Grid xmlns='https://github.com/avaloniaui' >
  28. <Grid.Transitions>
  29. <Transitions>
  30. <DoubleTransition Property='Opacity'
  31. Easing='CircularEaseIn'
  32. Duration='0:0:0.5' />
  33. </Transitions>
  34. </Grid.Transitions>
  35. </Grid>");
  36. Assert.Equal(1, parsed.Transitions.Count);
  37. Assert.Equal(Visual.OpacityProperty, parsed.Transitions[0].Property);
  38. }
  39. [Fact]
  40. public void Parser_Should_Override_Precompiled_Xaml()
  41. {
  42. var precompiled = new XamlIlClassWithPrecompiledXaml();
  43. Assert.Equal(Brushes.Red, precompiled.Background);
  44. Assert.Equal(1, precompiled.Opacity);
  45. var loaded = (XamlIlClassWithPrecompiledXaml)AvaloniaRuntimeXamlLoader.Parse(@"
  46. <UserControl xmlns='https://github.com/avaloniaui'
  47. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
  48. x:Class='Avalonia.Markup.Xaml.UnitTests.XamlIlClassWithPrecompiledXaml'
  49. Opacity='0'>
  50. </UserControl>");
  51. Assert.Equal(loaded.Opacity, 0);
  52. Assert.Null(loaded.Background);
  53. }
  54. [Fact]
  55. public void RelativeSource_TemplatedParent_Works()
  56. {
  57. using (UnitTestApplication.Start(TestServices.StyledWindow))
  58. {
  59. AvaloniaRuntimeXamlLoader.Load(@"
  60. <Application
  61. xmlns='https://github.com/avaloniaui'
  62. xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests;assembly=Avalonia.Markup.Xaml.UnitTests'
  63. >
  64. <Application.Styles>
  65. <Style Selector='Button'>
  66. <Setter Property='Template'>
  67. <ControlTemplate>
  68. <Grid><Grid><Grid>
  69. <Canvas>
  70. <Canvas.Background>
  71. <SolidColorBrush>
  72. <SolidColorBrush.Color>
  73. <MultiBinding>
  74. <MultiBinding.Converter>
  75. <local:XamlIlBugTestsBrushToColorConverter/>
  76. </MultiBinding.Converter>
  77. <Binding Path='Background' RelativeSource='{RelativeSource TemplatedParent}'/>
  78. <Binding Path='Background' RelativeSource='{RelativeSource TemplatedParent}'/>
  79. <Binding Path='Background' RelativeSource='{RelativeSource TemplatedParent}'/>
  80. </MultiBinding>
  81. </SolidColorBrush.Color>
  82. </SolidColorBrush>
  83. </Canvas.Background>
  84. </Canvas>
  85. </Grid></Grid></Grid>
  86. </ControlTemplate>
  87. </Setter>
  88. </Style>
  89. </Application.Styles>
  90. </Application>",
  91. null, Application.Current);
  92. var parsed = (Window)AvaloniaRuntimeXamlLoader.Parse(@"
  93. <Window
  94. xmlns='https://github.com/avaloniaui'
  95. xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests;assembly=Avalonia.Markup.Xaml.UnitTests'
  96. >
  97. <Button Background='Red' />
  98. </Window>
  99. ");
  100. var btn = ((Button)parsed.Content);
  101. btn.ApplyTemplate();
  102. var canvas = (Canvas)btn.GetVisualChildren().First()
  103. .VisualChildren.First()
  104. .VisualChildren.First()
  105. .VisualChildren.First();
  106. Assert.Equal(Brushes.Red.Color, ((ISolidColorBrush)canvas.Background).Color);
  107. }
  108. }
  109. [Fact]
  110. public void Event_Handlers_Should_Work_For_Templates()
  111. {
  112. using (UnitTestApplication.Start(TestServices.StyledWindow))
  113. {
  114. var w =new XamlIlBugTestsEventHandlerCodeBehind();
  115. w.ApplyTemplate();
  116. w.Show();
  117. Dispatcher.UIThread.RunJobs();
  118. var itemsPresenter = ((ItemsControl)w.Content).GetVisualChildren().FirstOrDefault();
  119. var item = itemsPresenter
  120. .GetVisualChildren().First()
  121. .GetVisualChildren().First()
  122. .GetVisualChildren().First();
  123. ((Control)item).DataContext = "test";
  124. Assert.Equal("test", w.SavedContext);
  125. }
  126. }
  127. [Fact]
  128. public void Custom_Properties_Should_Work_With_XClass()
  129. {
  130. var precompiled = new XamlIlClassWithCustomProperty();
  131. Assert.Equal("123", precompiled.Test);
  132. var loaded = (XamlIlClassWithCustomProperty)AvaloniaRuntimeXamlLoader.Parse(@"
  133. <UserControl xmlns='https://github.com/avaloniaui'
  134. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
  135. x:Class='Avalonia.Markup.Xaml.UnitTests.XamlIlClassWithCustomProperty'
  136. Test='321'>
  137. </UserControl>");
  138. Assert.Equal("321", loaded.Test);
  139. }
  140. static void AssertThrows(Action callback, Func<Exception, bool> check)
  141. {
  142. try
  143. {
  144. callback();
  145. }
  146. catch (Exception e) when (check(e))
  147. {
  148. return;
  149. }
  150. throw new Exception("Expected exception was not thrown");
  151. }
  152. public static object SomeStaticProperty { get; set; }
  153. [Fact]
  154. public void Bug2570()
  155. {
  156. SomeStaticProperty = "123";
  157. AssertThrows(() => AvaloniaRuntimeXamlLoader
  158. .Load(@"
  159. <UserControl
  160. xmlns='https://github.com/avaloniaui'
  161. xmlns:d='http://schemas.microsoft.com/expression/blend/2008'
  162. xmlns:tests='clr-namespace:Avalonia.Markup.Xaml.UnitTests'
  163. d:DataContext='{x:Static tests:XamlIlTests.SomeStaticPropery}'
  164. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'/>", typeof(XamlIlTests).Assembly,
  165. designMode: true),
  166. e => e.Message.Contains("Unable to resolve ")
  167. && e.Message.Contains(" as static field, property, constant or enum value"));
  168. }
  169. [Fact]
  170. public void Design_Mode_DataContext_Should_Be_Set()
  171. {
  172. SomeStaticProperty = "123";
  173. var loaded = (UserControl)AvaloniaRuntimeXamlLoader
  174. .Load(@"
  175. <UserControl
  176. xmlns='https://github.com/avaloniaui'
  177. xmlns:d='http://schemas.microsoft.com/expression/blend/2008'
  178. xmlns:tests='clr-namespace:Avalonia.Markup.Xaml.UnitTests'
  179. d:DataContext='{x:Static tests:XamlIlTests.SomeStaticProperty}'
  180. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'/>", typeof(XamlIlTests).Assembly,
  181. designMode: true);
  182. Assert.Equal(Design.GetDataContext(loaded), SomeStaticProperty);
  183. }
  184. [Fact]
  185. public void Attached_Properties_From_Static_Types_Should_Work_In_Style_Setters_Bug_2561()
  186. {
  187. using (UnitTestApplication.Start(TestServices.StyledWindow))
  188. {
  189. var parsed = (Window)AvaloniaRuntimeXamlLoader.Parse(@"
  190. <Window
  191. xmlns='https://github.com/avaloniaui'
  192. xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests;assembly=Avalonia.Markup.Xaml.UnitTests'
  193. >
  194. <Window.Styles>
  195. <Style Selector='TextBox'>
  196. <Setter Property='local:XamlIlBugTestsStaticClassWithAttachedProperty.TestInt' Value='100'/>
  197. </Style>
  198. </Window.Styles>
  199. <TextBox/>
  200. </Window>
  201. ");
  202. var tb = ((TextBox)parsed.Content);
  203. parsed.Show();
  204. tb.ApplyTemplate();
  205. Assert.Equal(100, XamlIlBugTestsStaticClassWithAttachedProperty.GetTestInt(tb));
  206. }
  207. }
  208. [Fact]
  209. public void Provide_Value_Target_Should_Provide_Clr_Property_Info()
  210. {
  211. var parsed = AvaloniaRuntimeXamlLoader.Parse<XamlIlClassWithClrPropertyWithValue>(@"
  212. <XamlIlClassWithClrPropertyWithValue
  213. xmlns='clr-namespace:Avalonia.Markup.Xaml.UnitTests'
  214. Count='{XamlIlCheckClrPropertyInfo ExpectedPropertyName=Count}'
  215. />", typeof(XamlIlClassWithClrPropertyWithValue).Assembly);
  216. Assert.Equal(6, parsed.Count);
  217. }
  218. [Fact]
  219. public void DataContextType_Resolution()
  220. {
  221. using (UnitTestApplication.Start(TestServices.StyledWindow))
  222. {
  223. var parsed = AvaloniaRuntimeXamlLoader.Parse<UserControl>(@"
  224. <UserControl
  225. xmlns='https://github.com/avaloniaui'
  226. xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests;assembly=Avalonia.Markup.Xaml.UnitTests'
  227. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:DataType='local:XamlIlBugTestsDataContext' />");
  228. }
  229. }
  230. [Fact]
  231. public void DataTemplates_Should_Resolve_Named_Controls_From_Parent_Scope()
  232. {
  233. using (UnitTestApplication.Start(TestServices.StyledWindow))
  234. {
  235. var parsed = (Window)AvaloniaRuntimeXamlLoader.Parse(@"
  236. <Window
  237. xmlns='https://github.com/avaloniaui'
  238. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
  239. >
  240. <StackPanel>
  241. <StackPanel.DataTemplates>
  242. <DataTemplate DataType='{x:Type x:String}'>
  243. <TextBlock Classes='target' Text='{Binding #txt.Text}'/>
  244. </DataTemplate>
  245. </StackPanel.DataTemplates>
  246. <TextBlock Text='Test' Name='txt'/>
  247. <ContentControl Content='tst'/>
  248. </StackPanel>
  249. </Window>
  250. ");
  251. parsed.DataContext = new List<string>() {"Test"};
  252. parsed.Show();
  253. parsed.ApplyTemplate();
  254. var cc = ((ContentControl)((StackPanel)parsed.Content).Children.Last());
  255. cc.ApplyTemplate();
  256. var templated = cc.GetVisualDescendants().OfType<TextBlock>()
  257. .First(x => x.Classes.Contains("target"));
  258. Assert.Equal("Test", templated.Text);
  259. }
  260. }
  261. [Fact]
  262. public void Should_Work_With_Base_Property()
  263. {
  264. var parsed = (ListBox)AvaloniaRuntimeXamlLoader.Load(@"
  265. <ListBox
  266. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
  267. xmlns='https://github.com/avaloniaui'
  268. xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests;assembly=Avalonia.Markup.Xaml.UnitTests'
  269. >
  270. <ItemsControl.ItemTemplate>
  271. <DataTemplate>
  272. <ContentControl Content='{Binding}' />
  273. </DataTemplate>
  274. </ItemsControl.ItemTemplate>
  275. </ListBox>");
  276. Assert.NotNull(parsed.ItemTemplate);
  277. }
  278. [Fact]
  279. public void Runtime_Loader_Should_Pass_Parents_From_ServiceProvider()
  280. {
  281. var sp = new TestServiceProvider
  282. {
  283. ParentsStack = new List<object>
  284. {
  285. new UserControl { Resources = { ["Resource1"] = new SolidColorBrush(Colors.Blue) } }
  286. }
  287. };
  288. var document = new RuntimeXamlLoaderDocument(@"
  289. <Button xmlns='https://github.com/avaloniaui' Background='{StaticResource Resource1}' />")
  290. {
  291. ServiceProvider = sp
  292. };
  293. var parsed = (Button)AvaloniaRuntimeXamlLoader.Load(document);
  294. Assert.Equal(Colors.Blue, ((ISolidColorBrush)parsed.Background!).Color);
  295. }
  296. [Fact]
  297. public void Style_Parser_Throws_For_Duplicate_Setter()
  298. {
  299. using var _ = UnitTestApplication.Start(TestServices.StyledWindow);
  300. var xaml = @"
  301. <Window xmlns='https://github.com/avaloniaui'
  302. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
  303. xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'>
  304. <Window.Styles>
  305. <Style Selector='TextBlock'>
  306. <Setter Property='Width' Value='100'/>
  307. <Setter Property='Height' Value='20'/>
  308. <Setter Property='Height' Value='30'/>
  309. </Style>
  310. </Window.Styles>
  311. <TextBlock/>
  312. </Window>";
  313. var diagnostics = new List<RuntimeXamlDiagnostic>();
  314. // We still have a runtime check in the StyleInstance class, but in this test we only care about compile warnings.
  315. Assert.Throws<InvalidOperationException>(() => AvaloniaRuntimeXamlLoader.Load(new RuntimeXamlLoaderDocument(xaml), new RuntimeXamlLoaderConfiguration
  316. {
  317. LocalAssembly = typeof(XamlIlTests).Assembly,
  318. DiagnosticHandler = diagnostic =>
  319. {
  320. diagnostics.Add(diagnostic);
  321. return diagnostic.Severity;
  322. }
  323. }));
  324. var warning = Assert.Single(diagnostics);
  325. Assert.Equal(RuntimeXamlDiagnosticSeverity.Warning, warning.Severity);
  326. Assert.StartsWith("Duplicate setter encountered for property 'Height'", warning.Title);
  327. }
  328. [Fact]
  329. public void Control_Theme_Parser_Throws_For_Duplicate_Setter()
  330. {
  331. using var _ = UnitTestApplication.Start(TestServices.StyledWindow);
  332. var xaml = @"
  333. <Window xmlns='https://github.com/avaloniaui'
  334. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
  335. xmlns:u='using:Avalonia.Markup.Xaml.UnitTests.Xaml'>
  336. <Window.Resources>
  337. <ControlTheme x:Key='MyTheme' TargetType='u:TestTemplatedControl'>
  338. <Setter Property='Width' Value='100'/>
  339. <Setter Property='Height' Value='20'/>
  340. <Setter Property='Height' Value='30'/>
  341. </ControlTheme>
  342. </Window.Resources>
  343. <u:TestTemplatedControl Theme='{StaticResource MyTheme}'/>
  344. </Window>";
  345. var diagnostics = new List<RuntimeXamlDiagnostic>();
  346. // We still have a runtime check in the StyleInstance class, but in this test we only care about compile warnings.
  347. Assert.Throws<InvalidOperationException>(() => AvaloniaRuntimeXamlLoader.Load(new RuntimeXamlLoaderDocument(xaml), new RuntimeXamlLoaderConfiguration
  348. {
  349. LocalAssembly = typeof(XamlIlTests).Assembly,
  350. DiagnosticHandler = diagnostic =>
  351. {
  352. diagnostics.Add(diagnostic);
  353. return diagnostic.Severity;
  354. }
  355. }));
  356. var warning = Assert.Single(diagnostics);
  357. Assert.Equal(RuntimeXamlDiagnosticSeverity.Warning, warning.Severity);
  358. Assert.StartsWith("Duplicate setter encountered for property 'Height'", warning.Title);
  359. }
  360. [Fact]
  361. public void Item_Container_Inside_Of_ItemTemplate_Should_Be_Warned()
  362. {
  363. using var _ = UnitTestApplication.Start(TestServices.StyledWindow);
  364. var xaml = new RuntimeXamlLoaderDocument(@"
  365. <ListBox xmlns='https://github.com/avaloniaui'
  366. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
  367. <ListBox.ItemTemplate>
  368. <DataTemplate>
  369. <ListBoxItem />
  370. </DataTemplate>
  371. </ListBox.ItemTemplate>
  372. </ListBox>");
  373. var diagnostics = new List<RuntimeXamlDiagnostic>();
  374. // We still have a runtime check in the StyleInstance class, but in this test we only care about compile warnings.
  375. var listBox = (ListBox)AvaloniaRuntimeXamlLoader.Load(xaml, new RuntimeXamlLoaderConfiguration
  376. {
  377. DiagnosticHandler = diagnostic =>
  378. {
  379. diagnostics.Add(diagnostic);
  380. return diagnostic.Severity;
  381. }
  382. });
  383. // ItemTemplate should still work as before, creating whatever object user put inside
  384. Assert.IsType<ListBoxItem>(listBox.ItemTemplate!.Build(null));
  385. // But invalid usage should be warned:
  386. var warning = Assert.Single(diagnostics);
  387. Assert.Equal(RuntimeXamlDiagnosticSeverity.Warning, warning.Severity);
  388. Assert.Equal("AVLN2208", warning.Id);
  389. }
  390. [Fact]
  391. public void Item_Container_Inside_Of_DataTemplates_Should_Be_Warned()
  392. {
  393. using var _ = UnitTestApplication.Start(TestServices.StyledWindow);
  394. var xaml = new RuntimeXamlLoaderDocument(@"
  395. <TabControl xmlns='https://github.com/avaloniaui'
  396. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
  397. <TabControl.DataTemplates>
  398. <DataTemplate x:DataType='x:Object'>
  399. <TabItem />
  400. </DataTemplate>
  401. </TabControl.DataTemplates>
  402. </TabControl>");
  403. var diagnostics = new List<RuntimeXamlDiagnostic>();
  404. // We still have a runtime check in the StyleInstance class, but in this test we only care about compile warnings.
  405. var tabControl = (TabControl)AvaloniaRuntimeXamlLoader.Load(xaml, new RuntimeXamlLoaderConfiguration
  406. {
  407. DiagnosticHandler = diagnostic =>
  408. {
  409. diagnostics.Add(diagnostic);
  410. return diagnostic.Severity;
  411. }
  412. });
  413. // ItemTemplate should still work as before, creating whatever object user put inside
  414. Assert.IsType<TabItem>(tabControl.DataTemplates[0]!.Build(null));
  415. // But invalid usage should be warned:
  416. var warning = Assert.Single(diagnostics);
  417. Assert.Equal(RuntimeXamlDiagnosticSeverity.Warning, warning.Severity);
  418. Assert.Equal("AVLN2208", warning.Id);
  419. }
  420. }
  421. public class XamlIlBugTestsEventHandlerCodeBehind : Window
  422. {
  423. public object SavedContext;
  424. public void HandleDataContextChanged(object sender, EventArgs args)
  425. {
  426. SavedContext = ((Control)sender).DataContext;
  427. }
  428. public XamlIlBugTestsEventHandlerCodeBehind()
  429. {
  430. AvaloniaRuntimeXamlLoader.Load(@"
  431. <Window x:Class='Avalonia.Markup.Xaml.UnitTests.XamlIlBugTestsEventHandlerCodeBehind'
  432. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
  433. xmlns='https://github.com/avaloniaui'
  434. xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests;assembly=Avalonia.Markup.Xaml.UnitTests'
  435. >
  436. <ItemsControl>
  437. <ItemsControl.ItemTemplate>
  438. <DataTemplate>
  439. <Button DataContextChanged='HandleDataContextChanged' Content='{Binding .}' />
  440. </DataTemplate>
  441. </ItemsControl.ItemTemplate>
  442. </ItemsControl>
  443. </Window>
  444. ", typeof(XamlIlBugTestsEventHandlerCodeBehind).Assembly, this);
  445. ((ItemsControl)Content).ItemsSource = new[] {"123"};
  446. }
  447. }
  448. public class XamlIlClassWithCustomProperty : UserControl
  449. {
  450. public string Test { get; set; }
  451. public XamlIlClassWithCustomProperty()
  452. {
  453. AvaloniaXamlLoader.Load(this);
  454. }
  455. }
  456. public class XamlIlBugTestsBrushToColorConverter : IMultiValueConverter
  457. {
  458. public object Convert(IList<object> values, Type targetType, object parameter, CultureInfo culture)
  459. {
  460. return (values[0] as ISolidColorBrush)?.Color;
  461. }
  462. }
  463. public class XamlIlBugTestsDataContext : INotifyPropertyChanged
  464. {
  465. public event PropertyChangedEventHandler PropertyChanged;
  466. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  467. {
  468. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  469. }
  470. }
  471. public class XamlIlClassWithPrecompiledXaml : UserControl
  472. {
  473. }
  474. public static class XamlIlBugTestsStaticClassWithAttachedProperty
  475. {
  476. public static readonly AvaloniaProperty<int> TestIntProperty = AvaloniaProperty
  477. .RegisterAttached<Control, int>("TestInt", typeof(XamlIlBugTestsStaticClassWithAttachedProperty));
  478. public static void SetTestInt(Control control, int value)
  479. {
  480. control.SetValue(TestIntProperty, value);
  481. }
  482. public static int GetTestInt(Control control)
  483. {
  484. return (int)control.GetValue(TestIntProperty);
  485. }
  486. }
  487. public class XamlIlCheckClrPropertyInfoExtension
  488. {
  489. public string ExpectedPropertyName { get; set; }
  490. public object ProvideValue(IServiceProvider prov)
  491. {
  492. var pvt = prov.GetService<IProvideValueTarget>();
  493. var info = (ClrPropertyInfo)pvt.TargetProperty;
  494. var v = (int)info.Get(pvt.TargetObject);
  495. return v + 1;
  496. }
  497. }
  498. public class XamlIlClassWithClrPropertyWithValue
  499. {
  500. public int Count { get; set; }= 5;
  501. }
  502. }