Jump to content
Software FX Community

Changing ItemSource in code and Template is lost


mgm

Recommended Posts

Hi,

When I change the ItemSource of a chart in code the template is lost that I assigned in xaml. I'm using your Pie2 template and a few other tricks from other posts to apply lines and labels to the pie slices. 

<cfx:Chart Name="chart1" Gallery="Pie" ItemsSource="{Binding Source={StaticResource SpendByChannelProvider}}" BorderThickness="0" >

<cfx:Chart.Titles>

<cfx:Title HorizontalAlignment="Left" Margin="5">

<TextBlock Text="Total Marketing Expenses" Background="Transparent" Foreground="{StaticResource FontBrush}" FontWeight="Bold" FontFamily="Calbiri" FontSize="16" HorizontalAlignment="Left"/>

</cfx:Title>

</cfx:Chart.Titles>

<cfx:SeriesAttributes BindingPath="Spend" Template="{StaticResource Pie2}">

<cfx:SeriesAttributes.PointLabels>

<cfx:PointLabelAttributes Visibility="Visible">

<cfx:PointLabelAttributes.Template>

<DataTemplate>

<Grid>

<Grid.RowDefinitions>

<RowDefinition></RowDefinition>

<RowDefinition></RowDefinition>

</Grid.RowDefinitions>

<Label Content="{Binding Path=DataItem.Channel}" Background="Transparent" Foreground="{StaticResource FontBrush}" FontWeight="Bold" FontFamily="Calbiri" FontSize="12"/>

<WrapPanel Grid.Row="1" Orientation="Horizontal" IsHitTestVisible="False" >

<Label Content="{Binding Path=DataItem.Spend, Converter={StaticResource fdc}, ConverterParameter='\{0:C\}'}" Background="Transparent" Foreground="{StaticResource FontBrush}" FontFamily="Calbiri" FontSize="9"/>

<Label Content ="(" Background="Transparent" Foreground="{StaticResource FontBrush}" FontFamily="Calbiri" FontSize="9"/>

<Label Background="Transparent" Foreground="{StaticResource FontBrush}" FontFamily="Calbiri" FontSize="9" HorizontalAlignment="Left" VerticalAlignment="Top">

<Label.Content>

<Binding Path="Self" Converter="{StaticResource MyTooltipConverter}" ConverterParameter="%p" />

</Label.Content>

</Label>

<Label Content ="%)" Background="Transparent" Foreground="{StaticResource FontBrush}" FontFamily="Calbiri" FontSize="9"/>

</WrapPanel></Grid>

</DataTemplate>

</cfx:PointLabelAttributes.Template>

</cfx:PointLabelAttributes>

</cfx:SeriesAttributes.PointLabels>

</cfx:SeriesAttributes>

</cfx:Chart>

My chart initializes with default data from an ObjectDataProvider class also in xaml. Once the user selects what they want to see from a combobox, I load  a new instance of the same class as I used for my ObjectDataProvider from the database and point the Chart ItemSource to it. The chart refreshes with the database data, (albeit not exactly right, but that's another post), then no longer has the template I assigned.DataAccess dao; // this is my database access object

// MessageBox.Show(SDBox.SelectedValue.ToString());dao = (DataAccess)App.Current.FindResource("dao");chart1.ItemsSource = dao.dvGetSpendByChannel((Int16)SDBox.SelectedValue);

chart1.AllSeries.Template = (

DataTemplate)FindResource("Pie2");

Any Ideas?

Thanks, Matt

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...