SizeToContent=WidthAndHeight : Window « Windows Presentation Foundation « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Windows Presentation Foundation » WindowScreenshots 
SizeToContent=WidthAndHeight
  

<Window x:Class="CustomDialogSample.SettingsDialog"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Settings"
  Height="200"
  Width="400"
  ResizeMode="CanResizeWithGrip"
  SizeToContent="WidthAndHeight"
  WindowStartupLocation="CenterOwner"
  FocusManager.FocusedElement="{Binding ElementName=myStringTextBox}"
  ShowInTaskbar="False">

  <StackPanel>
    <Label Target="{Binding ElementName=myStringTextBox}">Report _Folder</Label>
    <TextBox x:Name="myStringTextBox" Text="{Binding MyString}" />
    <Button x:Name="folderBrowseButton">...</Button>
    <Button HorizontalAlignment="Left" Name="reportColorButton">
      <StackPanel>
      <Rectangle Width="15" Height="15" SnapsToDevicePixels="True"
                   Fill="{StaticResource reportBrush}" />
        <AccessText Text="Report _Color..." Margin="10,0,0,0" />
      </StackPanel>
    </Button>
    <Button x:Name="okButton" IsDefault="True">OK</Button>
    <Button x:Name="cancelButton" IsCancel="True">Cancel</Button>
  </StackPanel>
</Window>
//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;


namespace CustomDialogSample {
    class DialogData : INotifyPropertyChanged {
      Color reportColor;
      public Color MyColor {
        get return reportColor; }
        set reportColor = value; Notify("MyColor")}
      }

      string mystring;
      public string MyString {
        get return mystring; }
        set mystring = value; Notify("MyString")}
      }

      public event PropertyChangedEventHandler PropertyChanged;
      void Notify(string prop) { ifPropertyChanged != null ) { PropertyChanged(this, new PropertyChangedEventArgs(prop))} }
    }
  public partial class SettingsDialog : System.Windows.Window {
    DialogData data = new DialogData();

    public Color MyColor {
      get return data.MyColor; }
      set data.MyColor = value; }
    }

    public string MyString {
      get return data.MyString; }
      set data.MyString = value; }
    }

    public SettingsDialog() {
      InitializeComponent();

      DataContext = data;

      reportColorButton.Click += reportColorButton_Click;
      folderBrowseButton.Click += folderBrowseButton_Click;
      okButton.Click += new RoutedEventHandler(okButton_Click);
    }

    void okButton_Click(object sender, RoutedEventArgs e) {
      DialogResult = true;
    }
    void reportColorButton_Click(object sender, RoutedEventArgs e) {
      System.Windows.Forms.ColorDialog dlg = new System.Windows.Forms.ColorDialog();
      Color color = MyColor;
      dlg.Color = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B);

      ifdlg.ShowDialog() == System.Windows.Forms.DialogResult.OK ) {
        MyColor = Color.FromArgb(dlg.Color.A, dlg.Color.R, dlg.Color.G, dlg.Color.B);
      }
    }

    void folderBrowseButton_Click(object sender, RoutedEventArgs e) {
      System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog();
      dlg.SelectedPath = MyString;
      ifdlg.ShowDialog() == System.Windows.Forms.DialogResult.OK ) {
        MyString = dlg.SelectedPath;
      }
    }

  }
}

   
    
  
Related examples in the same category
1.Basic DialogBoxBasic DialogBox
2.Window ResizeMode=CanMinimizeWindow ResizeMode=CanMinimize
3.Window BackgroundWindow Background
4.Set Window Height and WidthSet Window Height and Width
5.Control the Size of UI Elements in a FormControl the Size of UI Elements in a Form
6.Define the Tab Order of UI Elements in a FormDefine the Tab Order of UI Elements in a Form
7.About DialogAbout Dialog
8.About Dialog - Font Properties on RootAbout Dialog - Font Properties on Root
9.Window mouse down eventWindow mouse down event
10.Window Preview mouse down eventWindow Preview mouse down event
11.Window mouse up eventWindow mouse up event
12.Window OwnershipWindow Ownership
13.Launch a window with defined XAMLLaunch a window with defined XAML
14.Hosting a Windows Forms Property Grid in WPFHosting a Windows Forms Property Grid in WPF
15.Window.DragMoveWindow.DragMove
16.Window.CommandBindingsWindow.CommandBindings
17.Create a non-rectangular windowCreate a non-rectangular window
18.Order of precedence for sizing-related properties that are implemented by Window.Order of precedence for sizing-related properties that are implemented by Window.
19.Use Window Activated and Deactivated event to control a media fileUse Window Activated and Deactivated event to control a media file
20.Custom Element Binding WindowCustom Element Binding Window
21.ShutdownMode.OnLastWindowCloseShutdownMode.OnLastWindowClose
22.Window Loaded eventWindow Loaded event
23.Transparent WindowTransparent Window
24.Animated Video WindowAnimated Video Window
25.Close a window with Escape key pressedClose a window with Escape key pressed
26.Use WindowState to make full screen window, change resize mode to NoReSize
27.Window Closing and Closed eventWindow Closing and Closed event
28.Creating the main panel and add to Window in CodeCreating the main panel and add to Window in Code
29.Is Window activeIs Window active
30.Load the Data for a Window Asynchronously After It Has RenderedLoad the Data for a Window Asynchronously After It Has Rendered
31.Change window cursorChange window cursor
32.Show window based on button nameShow window based on button name
33.Listen to Window loaded eventListen to Window loaded event
34.Create Window and add window closing event handlerCreate Window and add window closing event handler
35.Activate window, close window, bring window to frontActivate window, close window, bring window to front
36.Do not handle events until Window is fully initialized.Do not handle events until Window is fully initialized.
37.Retrieving the mouse position relative to controls on a WindowRetrieving the mouse position relative to controls on a Window
38.Window On Mouse move eventWindow On Mouse move event
39.Window On Mouse up eventWindow On Mouse up event
40.Display window as dialogDisplay window as dialog
41.Load resource from Window ResourcesLoad resource from Window Resources
42.Windows Transparent BackgroundWindows Transparent Background
43.Save Window Position to RegistrySave Window Position to Registry
44.Center a Window to ScreenCenter a Window to Screen
45.Window Preview Key EventsWindow Preview Key Events
46.Non-Rectangular windowNon-Rectangular window
47.Set a Default ButtonSet a Default Button
48.Use the Grid to create a dialog box that uses the WPF layout APIUse the Grid to create a dialog box that uses the WPF layout API
49.ShowInTaskbar = false
50.ResizeMode=CanResizeWithGrip
51.Set the DataContext of a Window to a person objectSet the DataContext of a Window to a person object
52.DataContext with user defined object
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.