wpf chart print (system.windows.controls.datavisualization.toolkit) - wpf

I'm using a Bar Chart in the system.windows.controls.datavisualization.toolkit in a WPF/C# project. I would like to print this chart on a page, but it appears none of the binding are executed before printing. I end up with an empty square where the chart should be.
My XAML code looks like this (I've ommitted layout things)
<Grid x:Name="LayoutRoot">
<chartingToolkit:Chart x:Name="GUIchart" Style="{StaticResource TheGUIChartStyle}" FontSize="12">
<chartingToolkit:BarSeries x:Name="Series" ItemsSource="{Binding}">
<chartingToolkit:BarSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis x:Name="Xaxis" Minimum="0" Maximum="100" Interval="10" ShowGridLines="True" Orientation="X"/>
</chartingToolkit:BarSeries.DependentRangeAxis>
</chartingToolkit:BarSeries>
</chartingToolkit:Chart>
</Grid>
In c# I'm adding some titels and the bindings:
// set the X-axis title
Xaxis.Title = "Score in %";
// do the binding
Series.IndependentValuePath = "Name";
Series.DependentValuePath = "Score";
Series.ItemsSource = scores;
When debugging, this binding is actually executed before the chart is being add to the page. Nevertheless, I end up with an "empty" chart.

One possible cause for this the default fade-in animation in the chart. It is described in this forum post. You should be able to copy the default chart style from the source code and comment out the VSM animation.
You can download the source code for the latest DataVisualization development release here. Once you have the source, the file you want to look at is in the Core.WPF project - Themes\Generic.xaml. All the styles can be found there.
I have not actually tried it, but you should be able to copy the BarDataPoint style and remove the "RevealStates" VisualStateGroup.

Related

Create/Modify new WPF UI components

I want to change the graphical UI elements in WPF.
For example, I want to use a kind of a stack panel, but on the other hand I want to show my details in a star, or circle, etc.
Maybe setting a bitmap as a background, but I am working with lots of Data using zoom tool.
I found tutorials, documentation only for changing attributes of "old components", but nothing to make new ones.
Great resource for WPF beginners is www.wpftutorial.net
One of the best idea of WPF is separation of concerns:
UI Control = Logic in Code/XAML + Template
Using templates in XAML we can vary representation without modifying the control.
For example, if there is a need in creation of list of items. Then we can use ListBox control:
<ListBox>
<ListBoxItem>USA</ListBoxItem>
<ListBoxItem>UK</ListBoxItem>
</ListBox>
By default LisboxItem internal part is just binded TextBlock.
Now making UI modification without changing control source code:
<ListBox ImageSource="{Binding PathToSource}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource ProjectIcon}"/>
<TextBlock Text="{Binding Path=PropertyName}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
there appears image and text.
If there is a need in creating exclusive control then you can always use Custom Control.
Using raster images (e.g. PNG) is not good point, especially with zoom behaviour. If it is possible better to use vector images, that can be created in XAML or imported from SVG.

How to load user control with scroll bars in WPF?

I am trying to load a UserControl in the Window by using content control's content property in code behind. Every thing is fine, but my friends were not able to see all the control on the page due to resolution problem. How can I fix this to have scroll bar. I have tried putting ScrollViewer also, but it's not working. So, my solution works on the bigger Window which developed, but its not working on the Smaller resolution windows.
Sample code structure of loading the UserControl:
Window.Xaml
<ScrollViewer>
<ContentControl Name="ContentX" Margin="15,10,15,0" HorizontalAlignment="Center" VerticalAlignment="Center">
<Label FontWeight="Black" FontSize="18" FontFamily="Calibri">Some Content</Label>
</ContentControl>
</ScrollViewer>
Window.Xaml.cs
ContentX.Content = new UserControl();
UserControl.Xaml
//Contains the Code for User Control
I got it solved my Content Control is in another Grid Column where i fixed the width and height to be *, now i removed it it's working fine when i place it inside a Scroll Viewer

Embedding a ProgressBar in the TabItem header in WPF

The project I am working on generates a series of tabs for each item opened by the user. For some tabs in particular, certain database hits and calculations take an extended period of time. I was trying to determine a simple way to alert the user when the tab is ready and figured a progress bar would be as good or better than other ways I considered.
I am wondering if there is a way to embed a progress bar behind the header text of a TabItem or if I will need to build my own CustomControl. I have no clue how to do either, however, I think some examples of the latter exist in the project so I could try to figure that out through them.
You can define the layout of a TabItem pretty easily. This snippet of XAML will create a TabControl with one TabItem where the header of the TabItem has a ProgressBar with a TextBlock over the ProgressBar.
Of course, please customize this XAML to actually make it look good :-D
<TabControl>
<TabItem>
<TabItem.Header>
<Grid>
<ProgressBar Width="100" />
<TextBlock Text="Some Tab"/>
</Grid>
</TabItem.Header>
</TabItem>
</TabControl>

WP7 -- Context Menu Forces Black Background for Listbox

This is probably an easy one... I have a Listbox with a ContextMenu embedded in it, and every time the ContextMenu appears, the Listbox changes its background to opaque black. How do I prevent this from happening?
Here is some sample XAML:
<ListBox x:Name="FolderItems" ItemTemplate="{StaticResource ItemTemplate}" ItemContainerStyle="{StaticResource ItemListBox}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" ItemsSource="{Binding FolderItems}">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu
x:Name="FolderContextMenu"
Margin="20"
Background="WhiteSmoke"
BorderBrush="Black"
BorderThickness="1.0"
Closed="ContextMenu_Closed">
<toolkit:MenuItem Loaded="ContextMenuItem_Loaded"
Opacity="0.0" Margin="5" Background="Transparent"
Click="ContextMenuItem_Click" Name="ContextMenuDelete">
<toolkit:MenuItem.Header>
<TextBlock Text="delete" FontFamily="Segoe WP Bold"/>
</toolkit:MenuItem.Header>
</toolkit:MenuItem>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</ListBox>
Thanks
Update
I still haven't figured out why the entire listbox goes black when the context menu appears. I've set everything I can think of to a transparent brush.
I fixed this for my situation by opening up the toolkit (downloading the source: Silverlight Toolkit), and editing the color values myself in ContextMenu.cs . Then, I rebuilt and targeted the dll that I created rather than the one from the installer.
The only issue is that I will now need to do this application specific, but at least I can have a resolution. I believe also that if you set IsZoomEnabled=false, it won't have this behavior in the first place, but it's a different experience.
Here's my edited version: Pastebin
Check out the lines like this, they're the ones you'll need to change:
// Create a layer for the element's background
UIElement elementBackground = new Rectangle
{
Width = ownerElement.ActualWidth,
Height = ownerElement.ActualHeight,
Fill = new SolidColorBrush(Colors.White),
};
Good luck!
There's a simple way to do this. For some reason MS Access complements the colors when using a list box. If you set the foreground to red, it will show green, etc.
So, set the background color to black (0) and the foreground color to white (16777215). Counter-intuitive but it works is MS Access 2002.
Without seeing the template you're using I can't say for sure but you've probably hardcoded a background value but not considered the different states of the list items and the default state colour/value is being displayed

Remove the "blockiness" in Progress Bar in WPF

I want to remove the spaces between the blocks showing the progress.
I need it to be solid.
Code:
<ProgressBar Name="probar" Minimum="0" Height="40" BorderThickness="0"/>
Geetha
You need to redefine the template of the ProgressBar. Fortunately, it's not very complex... The simplest way is to extract the template with a tool like Style Snooper, the BAML Viewer Reflector Add-in, or Show Me The Template, and change the part that defines the background.

Resources