.
A Journal about the experiences I have developing little applications in C#, Perl, Html and Javascript and talking about things new things that I use. Always Geeky; Always Nerdy; Always poor Grammer!
I am a Software Analyst Developer working in Southport, England but living in Liverpool. I develop mainly in C# and ASP.Net. I have been developing comercial software for several years now. I maintain this site (hosted at SwitchMedia UK) as a way of exploring new technologies (such as AJAX) and just generally talking about techie geek issues. This site is developed through a host of Perl scripts and a liberal use of Javascript. I enjoy experimenting with new technologies and anything that I make I host here.
It is certanly possible to load different UI controls into a window at run-time. AVPad does this now to a degree. The real issue is going to be hooking the UI up to the code behind class(es). Loading XAML at runtime will not benifit from the event delegate generation and element naming that exist in the compiled code/BAML combination. If the XAML loader parses all properties and retains those as properties at run-time you could do a pass on the parse tree to hook these things up at run-time. I expect to see many applications offering this type of pluggable UI model as Avalon sinks into the developer community. --Michael
Essentially what is being implied here is that you can load up XAML at runtime but you will have to re-hook up the properties and the events at run-time because the loader. However, I have been thinking that getting the people who change the UI to create BAML is not all of a problem really. Therefore the app will be able to load a new compiled XAML file and use the same UI class on the backend.
An example might be we design two layouts each different from each other however they both share the same code-behind class:
<window class="AvalonApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/avalon/2005" x="http://schemas.microsoft.com/winfx/xaml/2005" text="AvalonApplication1">
<window class="AvalonApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/avalon/2005" x="http://schemas.microsoft.com/winfx/xaml/2005" text="AvalonApplication2">
This might work, I haven't tried it yet.
I am looking into loading a XAML file that simply contains resources at runtime and then assigning them also at runtime. I will let you know of the results.
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Uri resourceLocator =
new System.Uri("Window1.baml",
System.UriKind.RelativeOrAbsolute);
System.Windows.Application.LoadComponent(this,
resourceLocator);
}
When you're animating Width or Height, you have to specify both the From and the To, or you have to have specified the base value somewhere (e.g. on the element itself).
That's because when you don't specify the From or To it gets inferred from the base (unanimated) value. And in the case of Width and Height, the base value often isn't known until later when layout runs.
For example, in this page
<Page ...>
...
<Page.Storyboards>
<SetterTimeline TargetName="btn" Path="(Button.Width)" >
<DoubleAnimation From="50" />
</SetterTimeline>
</Page.Storyboards>
...
<Button Width="100" Name="btn" Background="Blue">Click</Button>
...
</Page>
the button's width is explicitly set on the <Button>, so the animation implicitly takes the width to 100 (from 50). But if you don't have the Width set in the <Button>, and don't have it anywhere else (e.g. in a Style), you have to have the From on the DoubleAnimation.
<Style TargetType="{x:Type MenuItem}" x:Key="{x:Type MenuItem}" >
<Setter Property="Width" Value="200" />
...
...
| Technorati Tags |
| xaml [feed], amazon [feed], windows api [feed], markup language [feed], wpf [feed], C# [feed], Chris sells [feed], Layout [feed] |
| Related Amazon Books |
| Windows API Bible: (UK)/(USA), Windows Forms Programming in C#: (UK)/(USA), Programming Windows Presentation Foundation: (UK)/(USA), Essential .Net Volume 1: (UK)/(USA), Mastering Visual Studio.NET: (UK)/(USA) |
| Related Images |
Point 3 I can deal with, but points 1 and 2 seem to be fundamental requirements for distinguishing between UI/Presentation and Application implementation. Ohwell, maybe other people will be able to recognise if this is a problem or correct me if I am wrong :).
I will post around the Internet and News Groups to see if any workarounds exist or other solutions.
I may post examples of what I think would be the correct way of doing things (ps I am normally wrong on most occasions ;))
| Technorati Tags |
| xaml [feed], amazon [feed], windows api [feed], markup language [feed], wpf [feed], C# [feed], Chris sells [feed], Layout [feed] |
| Related Amazon Books |
| Windows API Bible: (UK)/(USA), Windows Forms Programming in C#: (UK)/(USA), Programming Windows Presentation Foundation: (UK)/(USA), Essential .Net Volume 1: (UK)/(USA), Mastering Visual Studio.NET: (UK)/(USA) |
| Related Images |
Just a quick note or two about my previous post.
| Technorati Tags |
| xaml [feed], amazon [feed], windows api [feed], markup language [feed], wpf [feed], C# [feed], Chris sells [feed], Layout [feed] |
| Related Amazon Books |
| Windows API Bible: (UK)/(USA), Windows Forms Programming in C#: (UK)/(USA), Programming Windows Presentation Foundation: (UK)/(USA), Essential .Net Volume 1: (UK)/(USA), Mastering Visual Studio.NET: (UK)/(USA) |
| Related Images |
<Page xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005">
<DockPanel>
<Border Background="SkyBlue" BorderBrush="Black"
BorderThickness="1" DockPanel.Dock="Top">
<Menu Background="SkyBlue">
<MenuItem Header="Language" >
<MenuItem Header="English"
Name="english" />
<MenuItem Header="German"
Name="german" />
<MenuItem Header="Italian"
Name="italian"/>
</MenuItem>
</Menu>
</Border>
<Border Height="25" Background="SkyBlue"
BorderBrush="Black" BorderThickness="1"
DockPanel.Dock="Top">
</Border>
<Border Height="25" Background="#ffff99"
BorderBrush="Black" BorderThickness="1"
DockPanel.Dock="Bottom">
<TextBlock Foreground="black">Dock = "Bottom"
</TextBlock>
</Border>
<Border Width="200" Background="PaleGreen"
BorderBrush="Black" BorderThickness="1"
DockPanel.Dock="Left">
<TextBlock Foreground="black">Dock = "Left"
</TextBlock>
</Border>
<Border Background="White" BorderBrush="Black"
BorderThickness="1">
<TextFlow Background="LightSkyBlue"
Foreground="Black"
FontFamily="Palatino Linotype"
FontSize="14"
FontWeight="Normal" TextAlignment="Left"
TextWrap="Wrap">
<Paragraph>
<LineBreak/>
</Paragraph>
</TextFlow>
</Border>
</DockPanel>
<Page.Resources>
<Style TargetType="{x:Type MenuItem}"
x:Key="{x:Type MenuItem}" >
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type MenuItem}" >
<Grid Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}" >
<Rectangle x:Name="GelBackground"
Opacity="1" RadiusX="9" RadiusY="9"
Fill="{TemplateBinding ContentControl.Background}"
Stroke="VerticalGradient #cc000000 white "
StrokeThickness="1" />
<Rectangle x:Name="GelShine"
Margin="4,3,4,0"
VerticalAlignment="top"
RadiusX="6"
RadiusY="6" Opacity="1"
Fill="VerticalGradient
#ccffffff transparent"
Stroke="transparent"
Height="15px" ></Rectangle>
<ContentPresenter
x:Name="GelButtonContentShadow"
VerticalAlignment="center"
HorizontalAlignment="center"
Content="{TemplateBinding
ContentControl.Content}"
Margin="15,5,15,5"
TextBlock.Foreground="black"
RenderTransform="translate 0 1" />
<ContentPresenter
x:Name="GelButtonContentWhite"
VerticalAlignment="center"
HorizontalAlignment="center"
Content="{TemplateBinding
ContentControl.Content}"
Margin="15,5,15,5"
TextBlock.Foreground="white" />
</Grid>
<DataTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="MenuItem.Background"
Value="Red"></Setter>
</Trigger>
<Trigger Property="IsMouseOver"
Value="False">
<Setter Property="MenuItem.Background"
Value="SkyBlue"></Setter>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
</Page>
| Technorati Tags |
| xaml [feed], amazon [feed], windows api [feed], markup language [feed], wpf [feed], C# [feed], Chris sells [feed], Layout [feed] |
| Related Amazon Books |
| Windows API Bible: (UK)/(USA), Windows Forms Programming in C#: (UK)/(USA), Programming Windows Presentation Foundation: (UK)/(USA), Essential .Net Volume 1: (UK)/(USA), Mastering Visual Studio.NET: (UK)/(USA) |
| Related Images |