Skip to content

Instantly share code, notes, and snippets.

@jacksonh
Created August 10, 2010 18:03
Show Gist options
  • Save jacksonh/517704 to your computer and use it in GitHub Desktop.
Save jacksonh/517704 to your computer and use it in GitHub Desktop.
//
// if the textblock is in a managed control like the grid,
// its legal to set FontWeights with an int.
//
Grid grid = XamlReader.Load (@"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<TextBlock x:Name=""the_box"" FontWeight=""600"" />
</Grid>") as Grid;
Assert.IsNotNull (grid, "a1");
TextBlock block = grid.FindName ("the_box") as TextBlock;
Assert.IsNotNull (block, "a2");
Assert.AreEqual (FontWeights.SemiBold, block.FontWeight, "a3");
//
// But we can't just do this normally.
//
string bad_xaml = @"<TextBlock xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
FontWeight=""600"" />";
Assert.Throws<XamlParseException> (() => XamlReader.Load (bad_xaml));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment