mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-06 16:06:07 +02:00
merge main branch
This commit is contained in:
@@ -33,6 +33,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 67cce290-ca26-4c41-a797-b68aabc45479
|
||||
---
|
||||
# XAML Syntax In Detail
|
||||
|
||||
This topic defines the terms that are used to describe the elements of XAML syntax. These terms are used frequently throughout the remainder of this documentation, both for WPF documentation specifically and for the other frameworks that use XAML or the basic XAML concepts enabled by the XAML language support at the System.Xaml level. This topic expands on the basic terminology introduced in the topic [XAML in WPF](xaml-in-wpf.md).
|
||||
|
||||
This topic defines the terms that are used to describe the elements of XAML syntax. These terms are used frequently throughout the remainder of this documentation, both for WPF documentation specifically and for the other frameworks that use XAML or the basic XAML concepts enabled by the XAML language support at the System.Xaml level. This topic expands on the basic terminology introduced in the topic [XAML Overview (WPF)](/dotnet/desktop-wpf/fundamentals/xaml).
|
||||
@@ -69,7 +70,47 @@ For example, the following example is object element syntax that instantiates a
|
||||
|
||||
The following example is object element syntax that also includes XAML content property syntax. The inner text contained within will be used to set the <xref:System.Windows.Controls.TextBox> XAML content property, <xref:System.Windows.Controls.TextBox.Text%2A>.
|
||||
|
||||
[!code-xaml[XAMLOvwSupport#ThisIsATextBox](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/Page1.xaml#thisisatextbox)]
|
||||
For more information about the XAML language specification, download [\[MS-XAML\]](https://download.microsoft.com/download/0/A/6/0A6F7755-9AF5-448B-907D-13985ACCF53E/[MS-XAML].pdf) from the Microsoft Download Center.
|
||||
|
||||
<a name="xaml_and_clr"></a>
|
||||
## XAML and CLR
|
||||
XAML is a markup language. The common language runtime (CLR), as implied by its name, enables runtime execution. XAML is not by itself one of the common languages that is directly consumed by the CLR runtime. Instead, you can think of XAML as supporting its own type system. The particular XAML parsing system that is used by WPF is built on the CLR and the CLR type system. XAML types are mapped to CLR types to instantiate a run time representation when the XAML for WPF is parsed. For this reason, the remainder of discussion of syntax in this document will include references to the CLR type system, even though the equivalent syntax discussions in the XAML language specification do not. (Per the XAML language specification level, XAML types could be mapped to any other type system, which does not have to be the CLR, but that would require the creation and use of a different XAML parser.)
|
||||
|
||||
#### Members of Types and Class Inheritance
|
||||
Properties and events as they appear as XAML members of a WPF type are often inherited from base types. For example, consider this example: `<Button Background="Blue" .../>`. The <xref:System.Windows.Controls.Control.Background%2A> property is not an immediately declared property on the <xref:System.Windows.Controls.Button> class, if you were to look at the class definition, reflection results, or the documentation. Instead, <xref:System.Windows.Controls.Control.Background%2A> is inherited from the base <xref:System.Windows.Controls.Control> class.
|
||||
|
||||
The class inheritance behavior of WPF XAML elements is a significant departure from a schema-enforced interpretation of XML markup. Class inheritance can become complex, particularly when intermediate base classes are abstract, or when interfaces are involved. This is one reason that the set of XAML elements and their permissible attributes is difficult to represent accurately and completely using the schema types that are typically used for XML programming, such as DTD or XSD format. Another reason is that extensibility and type-mapping features of the XAML language itself preclude completeness of any fixed representation of the permissible types and members.
|
||||
|
||||
<a name="object_element_syntax"></a>
|
||||
## Object Element Syntax
|
||||
*Object element syntax* is the XAML markup syntax that instantiates a CLR class or structure by declaring an XML element. This syntax resembles the element syntax of other markup languages such as HTML. Object element syntax begins with a left angle bracket (\<), followed immediately by the type name of the class or structure being instantiated. Zero or more spaces can follow the type name, and zero or more attributes may also be declared on the object element, with one or more spaces separating each attribute name="value" pair. Finally, one of the following must be true:
|
||||
|
||||
- The element and tag must be closed by a forward slash (/) followed immediately by a right angle bracket (>).
|
||||
|
||||
- The opening tag must be completed by a right angle bracket (>). Other object elements, property elements, or inner text, can follow the opening tag. Exactly what content may be contained here is typically constrained by the object model of the element. The equivalent closing tag for the object element must also exist, in proper nesting and balance with other opening and closing tag pairs.
|
||||
|
||||
XAML as implemented by .NET has a set of rules that map object elements into types, attributes into properties or events, and XAML namespaces to CLR namespaces plus assembly. For WPF and .NET, XAML object elements map to .NET types as defined in referenced assemblies, and the attributes map to members of those types. When you reference a CLR type in XAML, you have access to the inherited members of that type as well.
|
||||
|
||||
For example, the following example is object element syntax that instantiates a new instance of the <xref:System.Windows.Controls.Button> class, and also specifies a <xref:System.Windows.FrameworkElement.Name%2A> attribute and a value for that attribute:
|
||||
|
||||
[!code-xaml[XAMLOvwSupport#SyntaxOE](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/Page1.xaml#syntaxoe)]
|
||||
|
||||
The following example is object element syntax that also includes XAML content property syntax. The inner text contained within will be used to set the <xref:System.Windows.Controls.TextBox> XAML content property, <xref:System.Windows.Controls.TextBox.Text%2A>.
|
||||
|
||||
[!code-xaml[XAMLOvwSupport#ThisIsATextBox](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/Page1.xaml#thisisatextbox)]
|
||||
|
||||
### Content Models
|
||||
A class might support a usage as a XAML object element in terms of the syntax, but that element will only function properly in an application or page when it is placed in an expected position of an overall content model or element tree. For example, a <xref:System.Windows.Controls.MenuItem> should typically only be placed as a child of a <xref:System.Windows.Controls.Primitives.MenuBase> derived class such as <xref:System.Windows.Controls.Menu>. Content models for specific elements are documented as part of the remarks on the class pages for controls and other WPF classes that can be used as XAML elements.
|
||||
|
||||
<a name="properties_of_object_elements"></a>
|
||||
## Properties of Object Elements
|
||||
Properties in XAML are set by a variety of possible syntaxes. Which syntax can be used for a particular property will vary, based on the underlying type system characteristics of the property that you are setting.
|
||||
|
||||
By setting values of properties, you add features or characteristics to objects as they exist in the run time object graph. The initial state of the created object from a object element is based on the parameterless constructor behavior. Typically, your application will use something other than a completely default instance of any given object.
|
||||
|
||||
<a name="attribute_syntax_properties"></a>
|
||||
## Attribute Syntax (Properties)
|
||||
Attribute syntax is the XAML markup syntax that sets a value for a property by declaring an attribute on an existing object element. The attribute name must match the CLR member name of the property of the class that backs the relevant object element. The attribute name is followed by an assignment operator (=). The attribute value must be a string enclosed within quotes.
|
||||
|
||||
### Content Models
|
||||
|
||||
@@ -232,10 +273,10 @@ The value of a XAML content property must be given either entirely before or ent
|
||||
|
||||
[!code-xaml[XAMLOvwSupport#SyntaxContent](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page5.xaml#syntaxcontent)]
|
||||
|
||||
Note that neither the property element for <xref:System.Windows.Controls.Panel.Children%2A> nor the element for the <xref:System.Windows.Controls.UIElementCollection> is required in the markup. This is a design feature of XAML so that recursively contained elements that define a [!INCLUDE[TLA2#tla_ui](../../../includes/tla2sharptla-ui-md.md)] are more intuitively represented as a tree of nested elements with immediate parent-child element relationships, without intervening property element tags or collection objects. In fact, <xref:System.Windows.Controls.UIElementCollection> cannot be specified explicitly in markup as an object element, by design. Because its only intended use is as an implicit collection, <xref:System.Windows.Controls.UIElementCollection> does not expose a public parameterless constructor and thus cannot be instantiated as an object element.
|
||||
Note that neither the property element for <xref:System.Windows.Controls.Panel.Children%2A> nor the element for the <xref:System.Windows.Controls.UIElementCollection> is required in the markup. This is a design feature of XAML so that recursively contained elements that define a UI are more intuitively represented as a tree of nested elements with immediate parent-child element relationships, without intervening property element tags or collection objects. In fact, <xref:System.Windows.Controls.UIElementCollection> cannot be specified explicitly in markup as an object element, by design. Because its only intended use is as an implicit collection, <xref:System.Windows.Controls.UIElementCollection> does not expose a public parameterless constructor and thus cannot be instantiated as an object element.
|
||||
|
||||
### Mixing Property Elements and Object Elements in an Object with a Content Property
|
||||
The XAML specification declares that a XAML processor can enforce that object elements that are used to fill the XAML content property within an object element must be contiguous, and must not be mixed. This restriction against mixing property elements and content is enforced by the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] XAML processors.
|
||||
The XAML specification declares that a XAML processor can enforce that object elements that are used to fill the XAML content property within an object element must be contiguous, and must not be mixed. This restriction against mixing property elements and content is enforced by the WPF XAML processors.
|
||||
|
||||
You can have a child object element as the first immediate markup within an object element. Then you can introduce property elements. Or, you can specify one or more property elements, then content, then more property elements. But once a property element follows content, you cannot introduce any further content, you can only add property elements.
|
||||
|
||||
@@ -243,7 +284,7 @@ The value of a XAML content property must be given either entirely before or ent
|
||||
|
||||
<a name="xaml_namespaces"></a>
|
||||
## XAML Namespaces
|
||||
None of the preceding syntax examples specified a XAML namespace other than the default XAML namespace. In typical [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] applications, the default XAML namespace is specified to be the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] namespace. You can specify XAML namespaces other than the default XAML namespace and still use similar syntax. But then, anywhere where a class is named that is not accessible within the default XAML namespace, that class name must be preceded with the prefix of the XAML namespace as mapped to the corresponding CLR namespace. For example, `<custom:Example/>` is object element syntax to instantiate an instance of the `Example` class, where the CLR namespace containing that class (and possibly the external assembly information that contains backing types) was previously mapped to the `custom` prefix.
|
||||
None of the preceding syntax examples specified a XAML namespace other than the default XAML namespace. In typical WPF applications, the default XAML namespace is specified to be the WPF namespace. You can specify XAML namespaces other than the default XAML namespace and still use similar syntax. But then, anywhere where a class is named that is not accessible within the default XAML namespace, that class name must be preceded with the prefix of the XAML namespace as mapped to the corresponding CLR namespace. For example, `<custom:Example/>` is object element syntax to instantiate an instance of the `Example` class, where the CLR namespace containing that class (and possibly the external assembly information that contains backing types) was previously mapped to the `custom` prefix.
|
||||
|
||||
For more information about XAML namespaces, see [XAML Namespaces and Namespace Mapping for WPF XAML](xaml-namespaces-and-namespace-mapping-for-wpf-xaml.md).
|
||||
|
||||
@@ -251,7 +292,7 @@ The value of a XAML content property must be given either entirely before or ent
|
||||
## Markup Extensions
|
||||
XAML defines a markup extension programming entity that enables an escape from the normal XAML processor handling of string attribute values or object elements, and defers the processing to a backing class. The character that identifies a markup extension to a XAML processor when using attribute syntax is the opening curly brace ({), followed by any character other than a closing curly brace (}). The first string following the opening curly brace must reference the class that provides the particular extension behavior, where the reference may omit the substring "Extension" if that substring is part of the true class name. Thereafter, a single space may appear, and then each succeeding character is used as input by the extension implementation, up until the closing curly brace is encountered.
|
||||
|
||||
The .NET XAML implementation uses the <xref:System.Windows.Markup.MarkupExtension> abstract class as the basis for all of the markup extensions supported by [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] as well as other frameworks or technologies. The markup extensions that [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] specifically implements are often intended to provide a means to reference other existing objects, or to make deferred references to objects that will be evaluated at run time. For example, a simple WPF data binding is accomplished by specifying the `{Binding}` markup extension in place of the value that a particular property would ordinarily take. Many of the WPF markup extensions enable an attribute syntax for properties where an attribute syntax would not otherwise be possible. For example, a <xref:System.Windows.Style> object is a relatively complex type that contains a nested series of objects and properties. Styles in WPF are typically defined as a resource in a <xref:System.Windows.ResourceDictionary>, and then referenced through one of the two WPF markup extensions that request a resource. The markup extension defers the evaluation of the property value to a resource lookup and enables providing the value of the <xref:System.Windows.FrameworkElement.Style%2A> property, taking type <xref:System.Windows.Style>, in attribute syntax as in the following example:
|
||||
The .NET XAML implementation uses the <xref:System.Windows.Markup.MarkupExtension> abstract class as the basis for all of the markup extensions supported by WPF as well as other frameworks or technologies. The markup extensions that WPF specifically implements are often intended to provide a means to reference other existing objects, or to make deferred references to objects that will be evaluated at run time. For example, a simple WPF data binding is accomplished by specifying the `{Binding}` markup extension in place of the value that a particular property would ordinarily take. Many of the WPF markup extensions enable an attribute syntax for properties where an attribute syntax would not otherwise be possible. For example, a <xref:System.Windows.Style> object is a relatively complex type that contains a nested series of objects and properties. Styles in WPF are typically defined as a resource in a <xref:System.Windows.ResourceDictionary>, and then referenced through one of the two WPF markup extensions that request a resource. The markup extension defers the evaluation of the property value to a resource lookup and enables providing the value of the <xref:System.Windows.FrameworkElement.Style%2A> property, taking type <xref:System.Windows.Style>, in attribute syntax as in the following example:
|
||||
|
||||
`<Button Style="{StaticResource MyStyle}">My button</Button>`
|
||||
|
||||
@@ -280,7 +321,7 @@ The value of a XAML content property must be given either entirely before or ent
|
||||
|||
|
||||
|-|-|
|
||||
|`<Page`|Opening object element of the root element|
|
||||
|`xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"`|The default ([!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)]) XAML namespace|
|
||||
|`xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"`|The default (WPF) XAML namespace|
|
||||
|`xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"`|The XAML language XAML namespace|
|
||||
|`x:Class="ExampleNamespace.ExampleCode"`|The partial class declaration that connects markup to any code-behind defined for the partial class|
|
||||
|`>`|End of object element for the root. Object is not closed yet because the element contains child elements|
|
||||
|
||||
+3
-3
@@ -16,12 +16,12 @@ This example shows how to use the methods in the <xref:System.Windows.Controls.C
|
||||
## Example
|
||||
The following example creates a <xref:System.Windows.Controls.Grid> element with a <xref:System.Windows.FrameworkElement.Name%2A> of `grid1`. The <xref:System.Windows.Controls.Grid> contains a <xref:System.Windows.Controls.StackPanel> that holds <xref:System.Windows.Controls.Button> elements, each controlled by a different collection method. When you click a <xref:System.Windows.Controls.Button>, it activates a method call in the code-behind file.
|
||||
|
||||
[!code-xaml[ColumnDefinitionsGrid#1](~/samples/snippets/csharp/VS_Snippets_Wpf/ColumnDefinitionsGrid/CSharp/Window1.xaml#1)]
|
||||
:::code language="xaml" source="snippets/manipulate-columns-and-rows-by-using-columndefinitionscollections/csharp/Window1.xaml" id="Snippet1":::
|
||||
|
||||
This example defines a series of custom methods, each corresponding to a <xref:System.Windows.Controls.Primitives.ButtonBase.Click> event in the [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)] file. You can change the number of columns and rows in the <xref:System.Windows.Controls.Grid> in several ways, which includes adding or removing rows and columns; and counting the total number of rows and columns. To prevent <xref:System.ArgumentOutOfRangeException> and <xref:System.ArgumentException> exceptions, you can use the error-checking functionality that the <xref:System.Windows.Controls.ColumnDefinitionCollection.RemoveRange%2A> method provides.
|
||||
|
||||
[!code-csharp[ColumnDefinitionsGrid#2](~/samples/snippets/csharp/VS_Snippets_Wpf/ColumnDefinitionsGrid/CSharp/Window1.xaml.cs#2)]
|
||||
[!code-vb[ColumnDefinitionsGrid#2](~/samples/snippets/visualbasic/VS_Snippets_Wpf/ColumnDefinitionsGrid/VisualBasic/Window1.xaml.vb#2)]
|
||||
:::code language="csharp" source="snippets/manipulate-columns-and-rows-by-using-columndefinitionscollections/csharp/Window1.xaml.cs" id="Snippet2":::
|
||||
:::code language="vb" source="snippets/manipulate-columns-and-rows-by-using-columndefinitionscollections/vb/Window1.xaml.vb" id="Snippet2":::
|
||||
|
||||
## See also
|
||||
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<Window
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="columndefinitions_grid.Window1"
|
||||
Title="ColumnDefinitions Sample">
|
||||
<Border BorderBrush="Black" Background="White" BorderThickness="2">
|
||||
<!-- <Snippet1> -->
|
||||
<DockPanel Margin="10,0,0,0">
|
||||
|
||||
<TextBlock FontSize="20" FontWeight="Bold" DockPanel.Dock="Top">Grid Column and Row Collections</TextBlock>
|
||||
<TextBlock DockPanel.Dock="Top">Click any of the buttons below to invoke the associated methods and properties of ColumnDefinition and RowDefinition Collections.</TextBlock>
|
||||
<Grid DockPanel.Dock="Top" HorizontalAlignment="Left" Name="grid1" ShowGridLines="true" Width="625" Height="400" Background="#b0e0e6">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
</Grid>
|
||||
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Width="625" DockPanel.Dock="Top">
|
||||
<Button Width="125" Click="addCol">Add Column</Button>
|
||||
<Button Width="125" Click="addRow">Add Row</Button>
|
||||
<Button Width="125" Click="clearCol">Clear All Columns</Button>
|
||||
<Button Width="125" Click="clearRow">Clear All Rows</Button>
|
||||
<Button Width="125" Click="removeCol">Remove One Column</Button>
|
||||
</StackPanel>
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Width="625" DockPanel.Dock="Top">
|
||||
<Button Width="125" Click="removeRow">Remove One Row</Button>
|
||||
<Button Width="125" Click="colCount">How Many Columns?</Button>
|
||||
<Button Width="125" Click="rowCount">How Many Rows?</Button>
|
||||
<Button Width="125" Click="rem5Col">Remove 5 Columns</Button>
|
||||
<Button Width="125" Click="rem5Row">Remove 5 Rows</Button>
|
||||
</StackPanel>
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Width="625" DockPanel.Dock="Top">
|
||||
<Button Width="125" Click="containsRow">Contains Row?</Button>
|
||||
<Button Width="125" Click="containsCol">Contains Column?</Button>
|
||||
<Button Width="125" Click="insertRowAt">Insert Row</Button>
|
||||
<Button Width="125" Click="insertColAt">Insert Column</Button>
|
||||
<Button Width="125" Click="colReadOnly">IsReadOnly?</Button>
|
||||
</StackPanel>
|
||||
<TextBlock DockPanel.Dock="Top" Name="tp1"/>
|
||||
<TextBlock DockPanel.Dock="Top" Name="tp2"/>
|
||||
<TextBlock DockPanel.Dock="Top" Name="tp3"/>
|
||||
<TextBlock DockPanel.Dock="Top" Name="tp4"/>
|
||||
<TextBlock DockPanel.Dock="Top" Name="tp5"/>
|
||||
</DockPanel>
|
||||
<!-- </Snippet1> -->
|
||||
</Border>
|
||||
</Window>
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
// <Snippet2>
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
|
||||
namespace columndefinitions_grid
|
||||
{
|
||||
public partial class Window1 : Window
|
||||
{
|
||||
RowDefinition rowDef1;
|
||||
ColumnDefinition colDef1;
|
||||
|
||||
// <Snippet11>
|
||||
private void addCol(object sender, RoutedEventArgs e)
|
||||
{
|
||||
colDef1 = new ColumnDefinition();
|
||||
grid1.ColumnDefinitions.Add(colDef1);
|
||||
}
|
||||
//</Snippet11>
|
||||
|
||||
// <Snippet3>
|
||||
private void addRow(object sender, RoutedEventArgs e)
|
||||
{
|
||||
rowDef1 = new RowDefinition();
|
||||
grid1.RowDefinitions.Add(rowDef1);
|
||||
}
|
||||
//</Snippet3>
|
||||
|
||||
// <Snippet12>
|
||||
private void clearCol(object sender, RoutedEventArgs e)
|
||||
{
|
||||
grid1.ColumnDefinitions.Clear();
|
||||
}
|
||||
//</Snippet12>
|
||||
|
||||
// <Snippet4>
|
||||
private void clearRow(object sender, RoutedEventArgs e)
|
||||
{
|
||||
grid1.RowDefinitions.Clear();
|
||||
}
|
||||
//</Snippet4>
|
||||
|
||||
// <Snippet15>
|
||||
private void removeCol(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (grid1.ColumnDefinitions.Count <= 0)
|
||||
{
|
||||
tp1.Text = "No More Columns to Remove!";
|
||||
}
|
||||
else
|
||||
{
|
||||
grid1.ColumnDefinitions.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
//</Snippet15>
|
||||
|
||||
// <Snippet5>
|
||||
private void removeRow(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (grid1.RowDefinitions.Count <= 0)
|
||||
{
|
||||
tp1.Text = "No More Rows to Remove!";
|
||||
}
|
||||
else
|
||||
{
|
||||
grid1.RowDefinitions.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
//</Snippet5>
|
||||
|
||||
// <Snippet17>
|
||||
private void colCount(object sender, RoutedEventArgs e)
|
||||
{
|
||||
tp2.Text = "The current number of Columns is: " + grid1.ColumnDefinitions.Count;
|
||||
}
|
||||
//</Snippet17>
|
||||
|
||||
// <Snippet7>
|
||||
private void rowCount(object sender, RoutedEventArgs e)
|
||||
{
|
||||
tp2.Text = "The current number of Rows is: " + grid1.RowDefinitions.Count;
|
||||
}
|
||||
//</Snippet7>
|
||||
|
||||
// <Snippet16>
|
||||
private void rem5Col(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (grid1.ColumnDefinitions.Count < 5)
|
||||
{
|
||||
tp1.Text = "There aren't five Columns to Remove!";
|
||||
}
|
||||
else
|
||||
{
|
||||
grid1.ColumnDefinitions.RemoveRange(0,5);
|
||||
}
|
||||
}
|
||||
// </Snippet16>
|
||||
|
||||
// <Snippet6>
|
||||
private void rem5Row(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (grid1.RowDefinitions.Count < 5)
|
||||
{
|
||||
tp1.Text = "There aren't five Rows to Remove!";
|
||||
}
|
||||
else
|
||||
{
|
||||
grid1.RowDefinitions.RemoveRange(0, 5);
|
||||
}
|
||||
}
|
||||
//</Snippet6>
|
||||
|
||||
// <Snippet8>
|
||||
private void containsRow(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (grid1.RowDefinitions.Contains(rowDef1))
|
||||
{
|
||||
tp2.Text = "Grid Contains RowDefinition rowDef1";
|
||||
}
|
||||
else
|
||||
{
|
||||
tp2.Text = "Grid Does Not Contain RowDefinition rowDef1";
|
||||
}
|
||||
}
|
||||
//</Snippet8>
|
||||
|
||||
// <Snippet13>
|
||||
private void containsCol(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (grid1.ColumnDefinitions.Contains(colDef1))
|
||||
{
|
||||
tp3.Text = "Grid Contains ColumnDefinition colDef1";
|
||||
}
|
||||
else
|
||||
{
|
||||
tp3.Text = "Grid Does Not Contain ColumnDefinition colDef1";
|
||||
}
|
||||
}
|
||||
//</Snippet13>
|
||||
|
||||
// <Snippet10>
|
||||
private void colReadOnly(object sender, RoutedEventArgs e)
|
||||
{
|
||||
tp4.Text = "RowDefinitionsCollection IsReadOnly?: " + grid1.RowDefinitions.IsReadOnly.ToString();
|
||||
tp5.Text = "ColumnDefinitionsCollection IsReadOnly?: " + grid1.ColumnDefinitions.IsReadOnly.ToString();
|
||||
}
|
||||
//</Snippet10>
|
||||
|
||||
// <Snippet9>
|
||||
private void insertRowAt(object sender, RoutedEventArgs e)
|
||||
{
|
||||
rowDef1 = new RowDefinition();
|
||||
grid1.RowDefinitions.Insert(grid1.RowDefinitions.Count, rowDef1);
|
||||
tp1.Text = "RowDefinition added at index position " + grid1.RowDefinitions.IndexOf(rowDef1).ToString();
|
||||
}
|
||||
//</Snippet9>
|
||||
|
||||
// <Snippet14>
|
||||
private void insertColAt(object sender, RoutedEventArgs e)
|
||||
{
|
||||
colDef1 = new ColumnDefinition();
|
||||
grid1.ColumnDefinitions.Insert(grid1.ColumnDefinitions.Count, colDef1);
|
||||
tp2.Text = "ColumnDefinition added at index position " + grid1.ColumnDefinitions.IndexOf(colDef1).ToString();
|
||||
}
|
||||
//</Snippet14>
|
||||
}
|
||||
}
|
||||
//</Snippet2>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<Application
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="columndefinitions_grid.app"
|
||||
Startup="AppStartingUp"
|
||||
/>
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Data;
|
||||
using System.Xml;
|
||||
using System.Configuration;
|
||||
|
||||
namespace columndefinitions_grid
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for app.xaml
|
||||
/// </summary>
|
||||
|
||||
public partial class app : Application
|
||||
{
|
||||
void AppStartingUp(object sender, StartupEventArgs e)
|
||||
{
|
||||
Window1 mainWindow = new Window1();
|
||||
mainWindow.InitializeComponent();
|
||||
mainWindow.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
|
||||
<PropertyGroup>
|
||||
<AssemblyName>SDKSample</AssemblyName>
|
||||
<TargetType>winexe</TargetType>
|
||||
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<ProductVersion>10.0.20821</ProductVersion>
|
||||
<ProjectGuid>{4BDD3A99-C878-405A-9108-7C948EA50659}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="UIAutomationProvider" />
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="UIAutomationTypes" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="app.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="Window1.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="app.xaml.cs">
|
||||
<DependentUpon>app.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Window1.xaml.cs">
|
||||
<DependentUpon>Window1.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"host": "visualstudio"
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
|
||||
<PropertyGroup>
|
||||
<AssemblyName>SDKSample</AssemblyName>
|
||||
<TargetType>winexe</TargetType>
|
||||
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<ProductVersion>10.0.20821</ProductVersion>
|
||||
<ProjectGuid>{9CD74B47-FC44-43A0-B18E-FFF7B4EA3EF8}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="UIAutomationProvider" />
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="UIAutomationTypes" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="app.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="Window1.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Window1.xaml.vb">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<Window
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="SDKSample.Window1"
|
||||
Title="ColumnDefinitions Sample">
|
||||
<Border BorderBrush="Black" Background="White" BorderThickness="2">
|
||||
<DockPanel Margin="10,0,0,0">
|
||||
|
||||
<TextBlock FontSize="20" FontWeight="Bold" DockPanel.Dock="Top">Grid Column and Row Collections</TextBlock>
|
||||
<TextBlock DockPanel.Dock="Top">Click any of the buttons below to invoke the associated methods and properties of ColumnDefinition and RowDefinition Collections.</TextBlock>
|
||||
|
||||
<Grid DockPanel.Dock="Top" HorizontalAlignment="Left" Name="grid1" ShowGridLines="True" Width="625" Height="400" Background="#b0e0e6">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
</Grid>
|
||||
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Width="625" DockPanel.Dock="Top">
|
||||
<Button Width="125" Click="addCol">Add Column</Button>
|
||||
<Button Width="125" Click="addRow">Add Row</Button>
|
||||
<Button Width="125" Click="clearCol">Clear All Columns</Button>
|
||||
<Button Width="125" Click="clearRow">Clear All Rows</Button>
|
||||
<Button Width="125" Click="removeCol">Remove One Column</Button>
|
||||
</StackPanel>
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Width="625" DockPanel.Dock="Top">
|
||||
<Button Width="125" Click="removeRow">Remove One Row</Button>
|
||||
<Button Width="125" Click="colCount">How Many Columns?</Button>
|
||||
<Button Width="125" Click="rowCount">How Many Rows?</Button>
|
||||
<Button Width="125" Click="rem5Col">Remove 5 Columns</Button>
|
||||
<Button Width="125" Click="rem5Row">Remove 5 Rows</Button>
|
||||
</StackPanel>
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Width="625" DockPanel.Dock="Top">
|
||||
<Button Width="125" Click="containsRow">Contains Row?</Button>
|
||||
<Button Width="125" Click="containsCol">Contains Column?</Button>
|
||||
<Button Width="125" Click="insertRowAt">Insert Row</Button>
|
||||
<Button Width="125" Click="insertColAt">Insert Column</Button>
|
||||
<Button Width="125" Click="colReadOnly">IsReadOnly?</Button>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock DockPanel.Dock="Top" Name="tp1"/>
|
||||
<TextBlock DockPanel.Dock="Top" Name="tp2"/>
|
||||
<TextBlock DockPanel.Dock="Top" Name="tp3"/>
|
||||
<TextBlock DockPanel.Dock="Top" Name="tp4"/>
|
||||
<TextBlock DockPanel.Dock="Top" Name="tp5"/>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
</Window>
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
' <Snippet2>
|
||||
Imports System.Windows
|
||||
Imports System.Windows.Controls
|
||||
Imports System.Windows.Documents
|
||||
|
||||
Namespace SDKSample
|
||||
|
||||
'@ <summary>
|
||||
'@ Interaction logic for Window1.xaml
|
||||
'@ </summary>
|
||||
|
||||
Partial Public Class Window1
|
||||
Inherits Window
|
||||
|
||||
Dim rowDef1 As New RowDefinition
|
||||
Dim colDef1 As New ColumnDefinition
|
||||
|
||||
' <Snippet11>
|
||||
Private Sub addCol(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
Dim colDef1 As New ColumnDefinition
|
||||
grid1.ColumnDefinitions.Add(colDef1)
|
||||
End Sub
|
||||
' </Snippet11>
|
||||
|
||||
'<Snippet3>
|
||||
Private Sub addRow(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
Dim rowDef1 As New RowDefinition()
|
||||
grid1.RowDefinitions.Add(rowDef1)
|
||||
End Sub
|
||||
'</Snippet3>
|
||||
|
||||
'<Snippet12>
|
||||
Private Sub clearCol(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
grid1.ColumnDefinitions.Clear()
|
||||
End Sub
|
||||
'</Snippet12>
|
||||
|
||||
'<Snippet4>
|
||||
Private Sub clearRow(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
grid1.RowDefinitions.Clear()
|
||||
End Sub
|
||||
'</Snippet4>
|
||||
|
||||
'<Snippet15>
|
||||
Private Sub removeCol(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
|
||||
If (grid1.ColumnDefinitions.Count <= 0) Then
|
||||
tp1.Text = "No More Columns to Remove!"
|
||||
Else
|
||||
grid1.ColumnDefinitions.RemoveAt(0)
|
||||
End If
|
||||
End Sub
|
||||
'</Snippet15>
|
||||
|
||||
'<Snippet5>
|
||||
Private Sub removeRow(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
If (grid1.RowDefinitions.Count <= 0) Then
|
||||
tp1.Text = "No More Rows to Remove!"
|
||||
Else
|
||||
grid1.RowDefinitions.RemoveAt(0)
|
||||
End If
|
||||
End Sub
|
||||
'</Snippet5>
|
||||
|
||||
'<Snippet17>
|
||||
Private Sub colCount(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
tp2.Text = "The current number of Columns is: " + grid1.ColumnDefinitions.Count.ToString()
|
||||
End Sub
|
||||
'</Snippet17>
|
||||
|
||||
'<Snippet7>
|
||||
Private Sub rowCount(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
tp2.Text = "The current number of Rows is: " + grid1.RowDefinitions.Count.ToString()
|
||||
End Sub
|
||||
'</Snippet7>
|
||||
|
||||
'<Snippet16>
|
||||
Private Sub rem5Col(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
If (grid1.ColumnDefinitions.Count < 5) Then
|
||||
tp1.Text = "There aren't five Columns to Remove!"
|
||||
Else
|
||||
grid1.ColumnDefinitions.RemoveRange(0, 5)
|
||||
End If
|
||||
End Sub
|
||||
'</Snippet16>
|
||||
|
||||
'<Snippet6>
|
||||
Private Sub rem5Row(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
If (grid1.RowDefinitions.Count < 5) Then
|
||||
tp1.Text = "There aren't five Rows to Remove!"
|
||||
Else
|
||||
grid1.RowDefinitions.RemoveRange(0, 5)
|
||||
End If
|
||||
End Sub
|
||||
'</Snippet6>
|
||||
|
||||
'<Snippet8>
|
||||
Private Sub containsRow(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
If (grid1.RowDefinitions.Contains(rowDef1)) Then
|
||||
tp2.Text = "Grid Contains RowDefinition rowDef1"
|
||||
Else
|
||||
tp2.Text = "Grid Does Not Contain RowDefinition rowDef1"
|
||||
End If
|
||||
End Sub
|
||||
'</Snippet8>
|
||||
|
||||
'<Snippet13>
|
||||
Private Sub containsCol(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
If (grid1.ColumnDefinitions.Contains(colDef1)) Then
|
||||
tp3.Text = "Grid Contains ColumnDefinition colDef1"
|
||||
Else
|
||||
tp3.Text = "Grid Does Not Contain ColumnDefinition colDef1"
|
||||
End If
|
||||
End Sub
|
||||
'</Snippet13>
|
||||
|
||||
'<Snippet10>
|
||||
Private Sub colReadOnly(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
tp4.Text = "RowDefinitionsCollection IsReadOnly?: " + grid1.RowDefinitions.IsReadOnly.ToString()
|
||||
tp5.Text = "ColumnDefinitionsCollection IsReadOnly?: " + grid1.ColumnDefinitions.IsReadOnly.ToString()
|
||||
End Sub
|
||||
'</Snippet10>
|
||||
|
||||
'<Snippet9>
|
||||
Private Sub insertRowAt(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
Dim rowDef1 As New RowDefinition
|
||||
grid1.RowDefinitions.Insert(grid1.RowDefinitions.Count, rowDef1)
|
||||
tp1.Text = "RowDefinition added at index position " + grid1.RowDefinitions.IndexOf(rowDef1).ToString()
|
||||
End Sub
|
||||
'</Snippet9>
|
||||
|
||||
'<Snippet14>
|
||||
Private Sub insertColAt(ByVal sender As Object, ByVal e As RoutedEventArgs)
|
||||
Dim colDef1 As New ColumnDefinition()
|
||||
grid1.ColumnDefinitions.Insert(grid1.ColumnDefinitions.Count, colDef1)
|
||||
tp2.Text = "ColumnDefinition added at index position " + grid1.ColumnDefinitions.IndexOf(colDef1).ToString()
|
||||
End Sub
|
||||
'</Snippet14>
|
||||
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
' </Snippet2>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<system.diagnostics>
|
||||
<sources>
|
||||
<!-- This section defines the logging configuration for My.Application.Log -->
|
||||
<source name="DefaultSource" switchName="DefaultSwitch">
|
||||
<listeners>
|
||||
<add name="FileLog"/>
|
||||
<!-- Uncomment the below section to write to the Application Event Log -->
|
||||
<!--<add name="EventLog"/>-->
|
||||
</listeners>
|
||||
</source>
|
||||
</sources>
|
||||
<switches>
|
||||
<add name="DefaultSwitch" value="Information"/>
|
||||
</switches>
|
||||
<sharedListeners>
|
||||
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>
|
||||
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
|
||||
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
|
||||
</sharedListeners>
|
||||
</system.diagnostics>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<Application
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
StartupUri="Window1.xaml"/>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"host": "visualstudio"
|
||||
}
|
||||
Reference in New Issue
Block a user