When I try to add multiple controls to a button it shows an error, how do I add multiple controls to a button?
Most of UI Elements in WPF can contain only a single child element, therefore, when you add a control to a button, an error stating that the control has a child and only one child can be added to the control is generated. To overcome this error add layouts like StackPanel inside the control and add multiple controls inside that StackPanel. The following code snippet will cause the error mentioned above. [XAML] <Button Height=’100′> <RadioButton Content=’Button1′ /> <RadioButton>Button 2</RadioButton>> </Button> A StackPanel can be used inside the button to have multiple controls inside the button. The following lines of code can be used to overcome the error. [XAML] <Button Height=’100′> <StackPanel Orientation=’Horizontal’> <RadioButton Content=’Button1’/> <RadioButton>Button 2</RadioButton> </StackPanel> </Button>
What is XAML?
XAML is an extensible markup language based on XML. XAML can be thought of as a declarative script for creating .NET 3.0 UI. It is particularly used in WPF as a user interface markup language to define UI elements, data binding, eventing and other features. It is also used in Windows Workflow Foundation (WF), in which the workflows themselves can be defined in XAML code.
What is WPF?
Windows Presentation Foundation (WPF) is the presentation subsystem feature of the .NET Framework 3.0. It is pre-installed in as a part of Windows Vista, It is also available for installation on Windows XP SP2 and Windows Server 2003. It supports the rich User Experiences (UX) that have been made possible by advances in hardware and technology since the GDI based UI architecture was initially designed in the 1980’s. Also refer to the separate section on XAML in this FAQ
How can I create a ProgressBar and use an animation to simulate the progress of an operation ?
This example creates a ProgressBar and uses an ’animation’ to simulate the progress of an operation. [XAML] <StatusBar Name=’sbar’ VerticalAlignment=’Bottom’ Background=’Beige’ > <StatusBarItem> <TextBlock>Downloading File</TextBlock> </StatusBarItem> <StatusBarItem> <ProgressBar Width=’100′ Height=’20’ Name=’progressBar1′> <ProgressBar.Triggers> <EventTrigger RoutedEvent=’ProgressBar.Loaded’> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName=’progressBar1′ Storyboard.TargetProperty=’Value’ From=’0′ To=’100′ Duration=’0:0:5′ /> </Storyboard> </BeginStoryboard> </EventTrigger> </ProgressBar.Triggers> </ProgressBar> </StatusBarItem> <StatusBarItem> <Separator/> </StatusBarItem> <StatusBarItem> <TextBlock>Online</TextBlock> </StatusBarItem> <StatusBarItem HorizontalAlignment=’Right’> <Image Source=’images\help.bmp’ Width=’16’ Height=’16’/> </StatusBarItem> </StatusBar>
What is the use of x:code ?
x:Code is a directive element defined in XAML. An x:Code directive element can contain inline programming code. The code that is defined inline can interact with the XAML on the same page. The following example illustrates inline C# code. Notice that the code is inside the x:Code element and that the code must be surrounded by <CDATA[…]]> to escape the contents for XML, so that an XAML processor (interpreting either the XAML schema or the WPF schema) will not try to interpret the contents literally as XML. [XAML] <Page xmlns=’http://schemas.microsoft.com/winfx/2006/xaml/presentation’ xmlns:x=’http://schemas.microsoft.com/winfx/2006/xaml’ x:Class=’MyNamespace.MyCanvasCodeInline’ > <Button Name=’button1′ Click=’Clicked’>Click Me!</Button> <x:Code><![CDATA[ void Clicked(object sender, RoutedEventArgs e) { button1.Content = ‘Hello World’; } ]]></x:Code> </Page>