Need help with Syntax
Posted: 10 Mar 2014, 11:05
Good Day,
I am starting work on a GUI using Noesis. I have no experience with XAML or WPF and I'm having some problems with some of the syntax. The tutorials have helped me to understand the basics, but the moment I deviate from them I'm in trouble. I think I mostly know 'what needs to happen', I just don't know the syntax to do it.
1) If I have extended an element (CustomGrid extending Grid, for example) what is the difference between starting the XAML file:
<CustomGrid>
vs.
<Grid x:Class='CustomGrid'>
2) In the examples you extend BaseComponent with functions that can be called via button click:
If you where to place this custom UserControl inside another element, how would you change the Button's properties to 'see' the function in MainPage1? It seems to search in Grid (the root element) by default.
3) In several examples you set the DataContext to an element declared as a Static Resource.
If a custom UserControl is created with a property and the above example is changed to:
How would one change the DataContext definition to locate the correct property?
4) In the tutorials you illustrate commands by binding the command property of a button to a property in a custom class. I would like to know who to use commands without such a binding. The following code works:
Where Execute and CanExecute are functions defined in CustomClass. However, I can only get this to work by using one of the pre-generated RoutedCommands (ApplicationCommands.Close in this case). How would I go about creating my own RoutedCommands, so that the following code can work:
Thanks a lot!
Regards,
Steven
I am starting work on a GUI using Noesis. I have no experience with XAML or WPF and I'm having some problems with some of the syntax. The tutorials have helped me to understand the basics, but the moment I deviate from them I'm in trouble. I think I mostly know 'what needs to happen', I just don't know the syntax to do it.
1) If I have extended an element (CustomGrid extending Grid, for example) what is the difference between starting the XAML file:
<CustomGrid>
vs.
<Grid x:Class='CustomGrid'>
2) In the examples you extend BaseComponent with functions that can be called via button click:
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MainPage1">
<UserControl.Resources>
<DataModel2 x:Name="dataModel" SimpleText="hello"/>
</UserControl.Resources>
<StackPanel DataContext="{StaticResource dataModel}"
HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="{Binding SimpleText}" />
<Button x:Name="btn" Content="Update Text" Click="OnBtnClick" />
</StackPanel>
</UserControl>
Code: Select all
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<UserControl x:Class="MainPage1">
<UserControl.Resources>
<DataModel2 x:Name="dataModel" SimpleText="hello"/>
</UserControl.Resources>
<StackPanel DataContext="{StaticResource dataModel}"
HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="{Binding SimpleText}" />
<Button x:Name="btn" Content="Update Text" Click="????????" />
</StackPanel>
</UserControl>
</Grid>
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Resources>
<DataModel1 x:Name="dataModel" SimpleText="hello"/>
</UserControl.Resources>
<StackPanel DataContext="{StaticResource dataModel}"
HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="{Binding SimpleText}" />
</StackPanel>
</UserControl>
Code: Select all
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl
x:Class='CustomUserControl'>
<StackPanel DataContext="??????"
HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="{Binding A_Property_In_CustomUserControl}" />
</StackPanel>
</UserControl>
</Grid>
4) In the tutorials you illustrate commands by binding the command property of a button to a property in a custom class. I would like to know who to use commands without such a binding. The following code works:
Code: Select all
<CustomClass
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" >
<CustomClass.CommandBindings>
<CommandBinding Command="ApplicationCommands.Close" Executed="Execute" CanExecute="CanExecute" />
</CustomClass.CommandBindings>
<StackPanel>
<Button Command="ApplicationCommands.Close" Content="Do Stuff" />
</StackPanel>
</GcsView>
Code: Select all
<CustomClass
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" >
<CustomClass.CommandBindings>
<CommandBinding Command="MyOwnCommands.DoStuff" Executed="Execute" CanExecute="CanExecute" />
</CustomClass.CommandBindings>
<StackPanel>
<Button Command="MyOwnCommands.DoStuff" Content="Do Stuff" />
</StackPanel>
</GcsView>
Regards,
Steven