[.net] XAML inheritence - i r confused

Started by
4 comments, last by way2lazy2care 12 years, 6 months ago
2 questions actually.
1. Why is this a "special interest" section? It seems fairly technical and the only reason I found it after looking through "the technical side"'s forums/sub-forums was by searching for XAML. Never expected it to be grouped way down here with Breaking In and IOTD. With all the new stuff being pushed into .net as of build it seems like it might be more relevant to game programming.

2. The actual XAML related question. So I am making a new fairly standard WPF app in part to learn XAML/WPF with all the new coolness I saw at build, and it is significantly confusing me. The largest confusing part for me seems to do with accessing and customizing controls that are primarily child components. In my case customizing charts right now.

So I have a line chart that I'm trying to just remove wasted space from. I'm using the .net included charts, and I'm using a custom ControlTemplate in an external project to reformat it. So far I've got the padding and title formated in a way that looks reasonable, but now I am trying to format the axes to take up a little less space, and I am getting confused on how I go about accessing them in xaml, though this confuses me in general outside this particular situation as well.

So the chart class is agnostic of chart type, and we add a LineSeries in the app's xaml after it has been formatted.

The Line Series appears to have an IndependentAxis and a DependentAxis, which are both of type CategoryAxis as far as I can tell. Inside those I can set their templates to alter the label to do what I want, but I am fairly dumbfounded about how to go about digging through the hierarchy of objects in xaml. In C# or whatever it would be similar to lineSeries.IndependentAxis.Template.Labels.DoStuffToTheLabels, but I find in xaml I am having to add a pretty ridiculous amount of code to get that deep into there. I feel like I must be doing something wrong or there must be a better way to alter a components children.

Here is something kind of what my code looks like to do the equivalent of the above.
[source lang="xaml"]
<Style x:Key="MyLineSeriesStyle" TargetType="chartingToolkit:LineSeries">
<Setter Property="Template" Value="{StaticResource MyLineSeriesTemplate}" />
</Style>

<!-- This is indented too much here, but I don't want to break the source tag and risk making it uglier ;(-->
<ControlTemplate x:Key="MyLineSeriesTemplate" TargetType="chartingToolkit:LineSeries">
<chartingToolkit:CategoryAxis>
<chartingToolkit:CategoryAxis.AxisLabelStyle>
<Style TargetType="chartingToolkit:AxisLabel">
<Setter Property="Template">
<Setter.Value>
<TextBlock "{TemplateBinding FormattedContent}">
<TextBlock.LayoutTransform>
<TranslateTransform Y="10" />
</TextBlock.LayoutTransform>
</TextBlock>
</Setter.Value>
</Setter>
</Style>
</chartingToolkit:CategoryAxis.AxisLabelStyle>
</chartingToolkit:CategoryAxis>
</ControlTemplate>

<!-- Then in the project xaml it looks like -->
<!-- MyChartStyle is the thing I use to get rid of the padding and legend in the chart itself. As we don't know about
The LineSeries/PieSeries/etc, we can't dig into those in the same style -->
<chartingToolkit:Chart x:Name="myGraph" Style="{StaticResource MyChartStyle}" Title="Latency">
<chartingToolkit:LineSeries Style="{StaticResource MyLineSeriesStyle}" DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" />
</chartingToolkit:Chart>
[/source]

That's like 8 levels into the xaml, just to get 3 levels into the object hierarchy. I feel like I am doing something wrong...

Also if anybody know up to date xaml tutorials I would be happy to look at them. I keep running into very very old ones that seem to be deprecated in newer versions of .net.
Advertisement
Anybody interested, the link below is helping tons with my above issues.

http://www.silverlight.net/learn/creating-ui/creating-controls-and-panels

Still kind of confused, but it's doing a great job of elaborating on how the xaml and cs files integrate together on a less than face value basis.
That's like 8 levels into the xaml, just to get 3 levels into the object hierarchy. I feel like I am doing something wrong

Maybe the mistake is using XAML. In the end I chose WPF for my first GUI with C#. I still feel that was the right choice rather than forms or XNA, but after a while I completely abandoned XAML. I found it messed up my programme structure. Every-things much cleaner witout it. I've just started using WCF for networking, seems good but again no XAML nonsense for me -everything in C#. No doubt there's many scenarios where code behind is minimal and XAML is highly productive and delivers good UI design, but I don't think its generally suited to the needs of game developers.

Maybe the mistake is using XAML. In the end I chose WPF for my first GUI with C#. I still feel that was the right choice rather than forms or XNA, but after a while I completely abandoned XAML. I found it messed up my programme structure. Every-things much cleaner witout it. I've just started using WCF for networking, seems good but again no XAML nonsense for me -everything in C#. No doubt there's many scenarios where code behind is minimal and XAML is highly productive and delivers good UI design, but I don't think its generally suited to the needs of game developers.


Just a note, I'm trying to make a tool not a game. That said, I have found that if I use xaml minimally and do more in the code behind it makes me more productive. Right now I lay out things that are simple in xaml and do anything even a little bit complicated in the code behind. I will also say that making your own components rather than trying to fit a square peg into a round hole helped a lot too. Though I would have liked some more modifiable chart controls on the part of whoever made the WPF chart controls.

[quote name='way2lazy2care' timestamp='1316546750' post='4863937']That's like 8 levels into the xaml, just to get 3 levels into the object hierarchy. I feel like I am doing something wrong

Maybe the mistake is using XAML. In the end I chose WPF for my first GUI with C#. I still feel that was the right choice rather than forms or XNA, but after a while I completely abandoned XAML. I found it messed up my programme structure. Every-things much cleaner witout it. I've just started using WCF for networking, seems good but again no XAML nonsense for me -everything in C#. No doubt there's many scenarios where code behind is minimal and XAML is highly productive and delivers good UI design, but I don't think its generally suited to the needs of game developers.
[/quote]

Once you do a bit more, you'll find there are certain things that are a lot easier in xaml than C#; styles and templates to start with.
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight

Once you do a bit more, you'll find there are certain things that are a lot easier in xaml than C#; styles and templates to start with.


Yea. I think much more of my problem was trying to use a gear as a wheel instead of just making a wheel myself. If that makes sense :/

This topic is closed to new replies.

Advertisement