How can I animate a Popup ?
In order to rotate the Popup, this example assigns a RotateTransform to the ‘RenderTransform’ property on the Canvas, which is the child element of the Popup. For the transform to work correctly, the example must set the ‘AllowsTransparency property’ to true. In addition, the Margin on the Canvas content must specify enough space for the Popup to rotate. [XAML] <Popup IsOpen='{Binding ElementName=myCheckBox,Path=IsChecked}’ PlacementTarget='{Binding ElementName=myCheckBox}’ AllowsTransparency=’True’ PopupAnimation=’Slide’ HorizontalOffset=’50’ VerticalOffset=’50’ > <!–The Margin set on the Canvas provides the additional area around the Popup so that the Popup is visible when it rotates.–> <Canvas Width=’100′ Height=’100′ Background=’DarkBlue’ Margin=’150′> <Canvas.RenderTransform> <RotateTransform x:Name=’theTransform’ /> </Canvas.RenderTransform> <TextBlock TextWrapping=’Wrap’ Foreground=’White’> Rotating Popup </TextBlock> </Canvas> </Popup>
How can I Save, Load, and Print RichTextBox Content ?
This can be done using the XAML code as given below. [XAML] <Page xmlns=’http://schemas.microsoft.com/winfx/2006/xaml/presentation’ xmlns:x=’http://schemas.microsoft.com/winfx/2006/xaml’ x:Class=’SDKSample.SaveLoadPrintRTB’ > <StackPanel> <RichTextBox Name=’richTB’> <FlowDocument> <Paragraph> <Run>Paragraph 1</Run> </Paragraph> </FlowDocument> </RichTextBox> <Button Click=’SaveRTBContent’>Save RTB Content</Button> <Button Click=’LoadRTBContent’>Load RTB Content</Button> <Button Click=’PrintRTBContent’>Print RTB Content</Button> </StackPanel> </Page> Below is the code-behind for the example. [C#] // Handle ‘Save RichTextBox Content’ button click. void SaveRTBContent(Object sender, RoutedEventArgs args) { // Send an arbitrary URL and file name string specifying // the location to save the XAML in. SaveXamlPackage(‘C:\\test.xaml’); } // Handle ‘Load RichTextBox Content’ button click. void LoadRTBContent(Object sender, RoutedEventArgs args) { // Send URL string specifying what file to retrieve XAML // from to load into the RichTextBox. LoadXamlPackage(‘C:\\test.xaml’); } // Handle ‘Print RichTextBox Content’ button click. void PrintRTBContent(Object sender, RoutedEventArgs args) { PrintCommand(); } // Save XAML in RichTextBox to a file specified by _fileName void SaveXamlPackage(string _fileName) { TextRange range; FileStream fStream; range = new TextRange(richTB.Document.ContentStart, richTB.Document.ContentEnd); fStream = new FileStream(_fileName, FileMode.Create); range.Save(fStream, DataFormats.XamlPackage); fStream.Close(); } // Load XAML into RichTextBox from a file specified by _fileName void LoadXamlPackage(string _fileName) { TextRange range; FileStream fStream; if (File.Exists(_fileName)) { range = new TextRange(richTB.Document.ContentStart, richTB.Document.ContentEnd); fStream = new FileStream(_fileName, FileMode.OpenOrCreate); range.Load(fStream, DataFormats.XamlPackage); fStream.Close(); } } // Print RichTextBox content private void PrintCommand() { PrintDialog pd = new PrintDialog(); if ((pd.ShowDialog() == true)) { //use either one of the below pd.PrintVisual(richTB as Visual, ‘printing as visual’); pd.PrintDocument((((IDocumentPaginatorSource)richTB.Document).DocumentPaginator), ‘printing as paginator’); } }
How do I create and save a RichTextFormat (RTF) file?
One way to do this is to use the ‘RichTextBox.SaveFile()’ method. [C#] private void button1_Click( object sender, EventArgs e ) { // get a file name from the user SaveFileDialog saveFile1 = new SaveFileDialog(); saveFile1.DefaultExt = ‘*.rtf’; saveFile1.Filter = ‘RTF Files|*.rtf’; if ( saveFile1.ShowDialog() == DialogResult.OK ) richTextBox1.SaveFile( saveFile1.FileName, RichTextBoxStreamType.RichText ) }
Can I bind two sliders in two different windows ?
You can bind two sliders, one on each of two windows and both of them linked to the same data. But they both have to be bound to the same instance of your data. [C#] yourDataType yourDataInstance = new YourDataType(); yourWindow1Instance.DataContext = yourDataInstance; yourWindow2Instance.DataContext= yourDataInstance; [XAML] <Window1> <Slider Value='{Binding ValueProperty}’ /> </Window1> <Window2> <Slider Value='{Binding ValueProperty}’ /> </Window2>
How can I customize the Ticks on a Slider ?
The ticks on the slider can be customized using the code given below. [XAML] <Slider Width=’100′ Value=’50’ Orientation=’Horizontal’ HorizontalAlignment=’Left’ IsSnapToTickEnabled=’True’ Maximum=’3′ TickPlacement=’BottomRight’ AutoToolTipPlacement=’BottomRight’ AutoToolTipPrecision=’2′ Ticks=’0, 1.1, 2.5, 3’/>