public TypographicPropertyMetadata(object defaultValue, DependencyProperty targetProperty, TypographyFeaturePage featurePage, string sampleTextTag) : base(defaultValue, _callback, targetProperty) { FeaturePage = featurePage; SampleTextTag = sampleTextTag; }
void InitializeFeaturePage(Grid grid, DependencyProperty chooserProperty, TypographyFeaturePage page) { if (page == null) { grid.Children.Clear(); grid.RowDefinitions.Clear(); } else { // Get the property value and metadata. object value = GetValue(chooserProperty); var metadata = (TypographicPropertyMetadata)chooserProperty.GetMetadata(typeof(FontChooser)); // Look up the sample text. string sampleText = (metadata.SampleTextTag != null) ? LookupString(metadata.SampleTextTag) : _defaultSampleText; if (page == _currentFeaturePage) { // Update the state of the controls. for (int i = 0; i < page.Items.Length; ++i) { // Check the radio button if it matches the current property value. if (page.Items[i].Value.Equals(value)) { var radioButton = (RadioButton)grid.Children[i * 2]; radioButton.IsChecked = true; } // Apply properties to the sample text block. var sample = (TextBlock)grid.Children[i * 2 + 1]; sample.Text = sampleText; ApplyPropertiesToObjectExcept(sample, chooserProperty); sample.SetValue(metadata.TargetProperty, page.Items[i].Value); } } else { grid.Children.Clear(); grid.RowDefinitions.Clear(); // Add row definitions. for (int i = 0; i < page.Items.Length; ++i) { var row = new RowDefinition(); row.Height = GridLength.Auto; grid.RowDefinitions.Add(row); } // Add the controls. for (int i = 0; i < page.Items.Length; ++i) { string tag = page.Items[i].Tag; var radioContent = new TextBlock(new Run(LookupString(tag))); radioContent.TextWrapping = TextWrapping.Wrap; // Add the radio button. var radioButton = new RadioButton(); radioButton.Name = tag; radioButton.Content = radioContent; radioButton.Margin = new Thickness(5.0, 0.0, 0.0, 0.0); radioButton.VerticalAlignment = VerticalAlignment.Center; Grid.SetRow(radioButton, i); grid.Children.Add(radioButton); // Check the radio button if it matches the current property value. if (page.Items[i].Value.Equals(value)) { radioButton.IsChecked = true; } // Hook up the event. radioButton.Checked += featureRadioButton_Checked; // Add the block with sample text. var sample = new TextBlock(new Run(sampleText)); sample.Margin = new Thickness(5.0, 5.0, 5.0, 0.0); sample.TextWrapping = TextWrapping.WrapWithOverflow; ApplyPropertiesToObjectExcept(sample, chooserProperty); sample.SetValue(metadata.TargetProperty, page.Items[i].Value); Grid.SetRow(sample, i); Grid.SetColumn(sample, 1); grid.Children.Add(sample); } // Add borders between rows. for (int i = 0; i < page.Items.Length; ++i) { var border = new Border(); border.BorderThickness = new Thickness(0.0, 0.0, 0.0, 1.0); border.BorderBrush = SystemColors.ControlLightBrush; Grid.SetRow(border, i); Grid.SetColumnSpan(border, 2); grid.Children.Add(border); } } } _currentFeature = chooserProperty; _currentFeaturePage = page; }