Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:dotnet:wpf:basic_controls [2012/02/10 11:30]
smayr [Border]
swdev:dotnet:wpf:basic_controls [2014/09/23 11:44] (current)
smayr [Expander]
Line 189: Line 189:
 <code csharp> <code csharp>
 myButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); myButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
 +</code>
 +
 +Tooltips on a button:
 +<code xml>
 +<Button Content="Tooltip Test" 
 +     ToolTipService.InitialShowDelay="1" ToolTipService.BetweenShowDelay="1" ToolTipService.ShowDuration="30000">
 +  <Button.ToolTip>
 +     <StackPanel Background="White">
 +         <Label FontWeight="Bold" Background="SteelBlue" Foreground="White" Content="Sample ToolTip Header"/>
 +         <TextBlock Width="200" TextWrapping="Wrap" Text="Sample ToolTip Body"/>
 +     </StackPanel>
 +  </Button.ToolTip>
 +</Button>
 </code> </code>
  
 More Creative: More Creative:
   * [[swdev:dotnet:Drop Down Button]]   * [[swdev:dotnet:Drop Down Button]]
- 
 == Cursor == == Cursor ==
  
Line 361: Line 373:
                       VerticalAlignment="Top" ExpandDirection="Down" Width="175">                       VerticalAlignment="Top" ExpandDirection="Down" Width="175">
                 <Grid Background="Cornsilk">                 <Grid Background="Cornsilk">
-                    <Grid.BitmapEffect+                    <Border Margin="5" BorderBrush="DarkGray" Background="White"  
-                        <DropShadowBitmapEffect /> +                            BorderThickness="1" CornerRadius="5"> 
-                    </Grid.BitmapEffect>+                        <Border.Effect> 
 +                            <DropShadowEffect BlurRadius="10" Opacity="0.5" /
 +                        </Border.Effect
 +                    </Border>
  
                     <Grid.RowDefinitions>                     <Grid.RowDefinitions>
Line 1120: Line 1135:
 <ProgressBar Margin="0" VerticalAlignment="Top" Height="20" <ProgressBar Margin="0" VerticalAlignment="Top" Height="20"
              Style="{DynamicResource SimpleProgressBar}"              Style="{DynamicResource SimpleProgressBar}"
-             Value="50">+             Value="50
 +             IsIndeterminate="false">
     <ProgressBar.Background>     <ProgressBar.Background>
        <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">        <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
Line 1130: Line 1146:
 </ProgressBar> </ProgressBar>
 </code> </code>
- 
 == RadioButton == == RadioButton ==
  
Line 1279: Line 1294:
 </code> </code>
  
 +''TextBlock'' with truncated text showing tooltip displaying full text :
 +<code xml>
 +<TextBlock Width="100" TextTrimming="CharacterEllipsis" 
 +          ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}">
 +This is a long sentence with text.
 +</TextBlock>
 +</code>
 +Alternatively, use a behavior: [[http://tranxcoder.wordpress.com/2008/10/12/customizing-lookful-wpf-controls-take-2|Customizing "Lookful" WPF controls]]
 == TextBox == == TextBox ==
  
Line 1303: Line 1326:
 } }
 </code> </code>
 +
 +''TextBox'' with a scrollbar:
 +<code xml>
 +<TextBox Name="txtBox" 
 +    ScrollViewer.HorizontalScrollBarVisibility="Auto"
 +    ScrollViewer.VerticalScrollBarVisibility="Auto"
 +    ScrollViewer.CanContentScroll="True">This is a TextBox</TextBox>
 +</code>             
 == TreeView == == TreeView ==
 <code xml> <code xml>
Line 1430: Line 1461:
 </code> </code>
  
 +== Timer ==
 +
 +In WPF, ''Timer'' runs on a separate thread from the UI thread, so you need to use ''DispatcherTimer'' instead:
 +
 +<code csharp>
 +void ActivateTimer()
 +{
 +  // using System.Windows.Threading;
 +  DispatcherTimer timer = new DispatcherTimer();
 +  timer.Interval = TimeSpan.FromSeconds(10);      // 10 seconds
 +  timer.Tick += new EventHandler(timer_Tick);     // Subscribe to Tick event handler
 +  timer.Start();
 +}
 +
 +void timer_Tick(object sender, EventArgs e)
 +{
 +  // Do something every tick
 +}
 +</code>
 == URI == == URI ==
  
Line 1441: Line 1491:
  
 More information: [[http://msdn.microsoft.com/en-us/library/aa970069.aspx|MSDN: Pack URIs in WPF]] More information: [[http://msdn.microsoft.com/en-us/library/aa970069.aspx|MSDN: Pack URIs in WPF]]
- 
 == WebBrowser == == WebBrowser ==
  
Line 1462: Line 1511:
  
    // Local web page    // Local web page
 +   // NOTE: Use siteoforigin for local files.  Only files relative to application folder can be opened
 +   //       No GET parameters can be passed through URI.
 +   // More Reading: http://www.dotnetfunda.com/articles/article840-working-with-webbrowser-in-wpf.aspx
    //HtmlBrowserReport.Navigate(new Uri("pack://siteoforigin:,,,/htmlpage1.htm", UriKind.RelativeOrAbsolute));    //HtmlBrowserReport.Navigate(new Uri("pack://siteoforigin:,,,/htmlpage1.htm", UriKind.RelativeOrAbsolute));
    HtmlBrowserReport.Navigate(new Uri("pack://siteoforigin:,,,/reports/report.htm", UriKind.RelativeOrAbsolute));  // located in subdir "reports"    HtmlBrowserReport.Navigate(new Uri("pack://siteoforigin:,,,/reports/report.htm", UriKind.RelativeOrAbsolute));  // located in subdir "reports"
 } }
 +</code>
 +
 +Execute a JavaScript routine from C#: (see more: [[http://www.dotnetfunda.com/articles/article840-working-with-webbrowser-in-wpf.aspx|Working with WebBrowser in WPF]])
 +<code csharp>
 +public class TSampleApp
 +{
 +  // Fields
 +  private WebBrowser aWebBrowser;  
 +  . . .
 +
 +  // Constructor
 +  public TSampleApp()
 +  {
 +    aWebBrowser = new WebBrowser();
 +    aWebBrowser.LoadCompleted -= new LoadCompletedEventHandler(aWebBrowser_LoadCompleted);
 +    aWebBrowser.LoadCompleted += new LoadCompletedEventHandler(aWebBrowser_LoadCompleted);
 +  }
 +  
 +  public void LoadWebPage(string aWebPage)
 +  {
 +    // Load a webpage using Source property or Navigate() method
 +    
 +    // Load an external website
 +    aWebBrowser.Navigate("http://www.example.com");
 +    aWebBrowser.Navigate(new Uri("http://www.example.com", UriKind.RelativeOrAbsolute));
 +
 +    // Load a local file
 +    aWebBrowser.Navigate("Products/Catalog/prodspec.htm");
 +    aWebBrowser.Source = new Uri(@"pack://siteoforigin:,,,/Products/Catalog/prodspec.htm", UriKind.RelativeOrAbsolute);
 +   
 +  }
 +                
 +  void aWebBrowser_LoadCompleted(object sender, NavigationEventArgs e)
 +  {
 +    // Call JavaScript routine after the document has been loaded completely
 +    // Example:
 +    //aWebBrowser.InvokeScript("getAlert");  // call javascript function with no params
 +    //aWebBrowser.InvokeScript("LoadDoc", new object[] { "prod_Name.pdf" });  // call javascript function with params
 +    string AppDir = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
 +    string ProdSpecPDFFilePath = "file:///" + System.IO.Path.Combine(AppDir, string.Format(@"Products\Catalog\{0}.pdf", _SelectedProduct.Code)).Replace("\\", "\\\\");
 +            aWebBrowser.InvokeScript("LoadDoc", new object[] { ProdSpecPDFFilePath });
 +  }
 +}  
 +</code>
 +
 +Sample HTML page with JavaScript to call:
 +<code js>
 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 +<html>
 +<head>
 +    <title>This page comes from Stream</title>
 +
 +    <script type="text/javascript">
 + function getAlert()
 + {
 +     alert("Hi the page is loaded!!!");
 + }
 + window.onload = getAlert;
 +
 + function LoadDoc(message){
 +     document.write("Message : " + message);
 + }
 +    </script>
 +
 +</head>
 +<body>
 +    <input type="text" id="txtMessage" />
 +</body>
 +</html>
 </code> </code>
 == Window == == Window ==