WPF menu not shown in proper view - wpf

I am generating menu items dynamically, following is my menu
<ItemsControl x:Name="MainToolbar"
cal:RegionManager.RegionName="{x:Static inf:RegionNames.MainToolBarRegion}"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Margin="0,10,841,0"
RenderTransformOrigin="-0.133,-5.917"
Height="28"
Width="35">
<ItemsControl.RenderTransform>
<TransformGroup>
<ScaleTransform />
<SkewTransform />
<RotateTransform />
<TranslateTransform />
</TransformGroup>
</ItemsControl.RenderTransform>
<Menu IsMainMenu="True"
Margin="0,0,0,0"
Height="28"
ItemsSource="{Binding Path=Menu}"
Width="400">
<Menu.Resources>
<Style x:Key="ThemeMenuItemStyle"
TargetType="MenuItem"
BasedOn="{StaticResource KV_MenuItem}">
<Setter Property="Header"
Value="{Binding Path=Text}"></Setter>
<Setter Property="Command"
Value="{Binding Path=Command}" />
<Setter Property="IsCheckable"
Value="True" />
<Setter Property="MinWidth"
Value="80" />
</Style>
</Menu.Resources>
</Menu>
</ItemsControl>
My menu items added to the menu correctly (from my another service)
The problem here is my generated view not showing properly, means i can only see a small box where rest view is clipped off. (it does not expand to its contents). how can i see my full menu shown?

In your ItemsControl declaration remove the Width declaration and possible the Margin as well. Those properties maybe restricting your view.

Related

WPF/Designer: ItemContainerStyle RadioButton as ToggleButton. Works when in runtime but fails in designer

I have a ItemsControl with an ItemContainerStyle based on ToggleButton.
This works just fine at runetime, but it casts an error in the designer. (So I have to comment it out if i want to use the designer)
I populate this with code behind. Using RadioButtons.
InvalidOperationException: A style intended for type 'RadioButton' cannot be applied to type 'ContentPresenter'.
Iv lived with this for along time now, but its time to see if there is a solution!
Any ideas how to work around this?
<ItemsControl x:Name="BrushButtons"
Grid.Row="1"
Grid.Column="3"
VerticalAlignment="Bottom">
<ItemsPanelTemplate>
<StackPanel VerticalAlignment="Bottom" Orientation="Vertical" />
</ItemsPanelTemplate>
<ItemsControl.ItemContainerStyle>
<Style BasedOn="{StaticResource {x:Type ToggleButton}}" TargetType="{x:Type RadioButton}">
<Setter Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="-90" />
</Setter.Value>
</Setter>
<Setter Property="Width" Value="70" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
Kind Regards.

In multiple Y axis graph, the axis shift issue in wpf

I have chart control,depends upon the selection i have to plot a graph,here is screen shot
First case i have selected, 2 inputs and second case given 1 input. as above images it shifts axis.If i refresh it will be the proper position.
<chartingToolkit:Chart Name="lineChart" BorderThickness="0" Padding="0"
Grid.IsSharedSizeScope="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<chartingToolkit:Chart.LegendStyle>
<Style TargetType="Control">
<Setter Property="Template" Value="{x:Null}"/>
</Style>
</chartingToolkit:Chart.LegendStyle>
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Orientation="X" Minimum="0" Maximum="{Binding MaxX}" Title="Time (Minutes)" />
</chartingToolkit:Chart.Axes>
<chartingToolkit:LineSeries Title="Oxygen" DependentValuePath="Value" IndependentValuePath="Key" Visibility="{Binding O2.GraphVisibility}"
ItemsSource="{Binding O2.TGraph,UpdateSourceTrigger=PropertyChanged}" IsSelectionEnabled="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Padding="0" >
<chartingToolkit:LineSeries.DataPointStyle>
<Style TargetType="chartingToolkit:LineDataPoint">
<Setter Property="Template" Value="{x:Null}" />
<Setter Property="Background" Value="{StaticResource graphO2}"/>
</Style>
</chartingToolkit:LineSeries.DataPointStyle>
<chartingToolkit:LineSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis Title="{Binding O2.YTitle}" Foreground="{StaticResource graphO2}" Visibility="{Binding O2.YVisibility}" Maximum="{Binding O2.MaxY}" Orientation="Y" Location="{Binding O2.YLocation}" />
</chartingToolkit:LineSeries.DependentRangeAxis>
</chartingToolkit:LineSeries>
</chartingToolkit:Chart>
Using WPF Toolkit Data Visualization for graph.Please help me solve this issue.Coding side using MVVM architecuture.
It seems that chart doesn't refreshe in proper way, when you change input or modify dependency properties.
At least in LightningChart Visualization component, you can disable chart rendering - modify properties - continue rendering. You can easily prevent such bugs.
Try that and see the result. It has free demoapp with examples and available code. Can help you.

How to write a style for HyperlinkButton Shadow effect in Silverlight

I have a styled HyperlinkButton as per custom need as follow:
<HyperlinkButton Tag="Transactions/HomeWorkPage"
Background="#E9E9EB" Foreground="Black">
<HyperlinkButton.Effect>
<DropShadowEffect Direction="270" Opacity="0.35" ShadowDepth="3"/>
</HyperlinkButton.Effect>
<StackPanel Orientation="Horizontal">
<Image Source="/SchoolMgmt;component/Assets/Images/R_Homework.png"
Margin="10,0,1,0"/>
<telerik:Label Content="Home Work" CharacterSpacing="25"
telerik:StyleManager.Theme="{Binding SelectedTheme,Mode=TwoWay}"
FontSize="12" FontFamily="Arial Rounded MT" Margin="3"/>
</StackPanel>
</HyperlinkButton>
Now with satisfy with the result I started to write a style resource for this so that I can use wherever I want.
This is I am able to write:
<Style x:Name="QuickLinkStyle" TargetType="HyperlinkButton">
<Setter Property="Background" Value="#E9E9EB"/>
<Setter Property="Foreground" Value="Black"/>
</Style>
I am not able to convert following into style
<HyperlinkButton.Effect>
<DropShadowEffect Direction="270" Opacity="0.35" ShadowDepth="3"/>
</HyperlinkButton.Effect>
I am not a designer and not using expression blend for writing a style. I tried to googled it. But all I able to find out is DataTemplate , VisualStates etc. Its very confusing.
So this is not working?
<Style x:Name="QuickLinkStyle" TargetType="HyperlinkButton">
...
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect .../>
</Setter.Value>
</Setter>
</Style>

ComboBox highlighting

I have a problem with my combobox I'm trying to customize. It is in a UserControl, and i want its BorderBrush property to change from Transparent to White when the mouse is over it (fade in/out would be bonus).
But I can't seem to get the proper Trigger syntax to do so... now I feel confused and I'm probably missing something obvious here.
Here is the combobox in question:
<ComboBox x:Name="comboEmiCategories" ItemsSource="{Binding}" Background="Transparent" Height="15px" Width="30px" BorderBrush="Transparent" Padding="-2">
<ComboBox.Resources>
<sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">0</sys:Double>
</ComboBox.Resources>
<ComboBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" Stretch="UniformToFill" Height="15px" Width="30px" Margin="0" />
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="ComboBox.IsMouseOver" Value="True">
<Setter Property="ComboBox.BorderBrush" Value="White" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ComboBox.Template>
</ComboBox>
The trigger isn't working, even worse actually, if i don't comment out the whole ComboBox.Template part, the control disappears.
The main goal would be to have a ComboBox that stacks images and allows the user to select one out of a list, with nothing else than those images shown.
Thanks.
EDIT:
Mario's solution of putting it within a style works, but is it the only way to do this?
Try to place the below xaml within the Resources section of your window/usercontrol.
<Style x:Name="cbStyle" TargetType="ComboBox">
<Setter Property="BorderBrush" Value="Transparent" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
Of course you must refer this style in the ComboBox element. Also cut anything within the ControlTemplate, which is useless.
EDIT: your ComboBox section should look as follows:
<ComboBox x:Name="comboEmiCategories" ItemsSource="{Binding}" Height="15px" Width="30px" Style="{StaticResource cbStyle}" Padding="-2">
<ComboBox.Resources>
<sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">0</sys:Double>
</ComboBox.Resources>
<ComboBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" Stretch="UniformToFill" Height="15px" Width="30px" Margin="0" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Also put the Style declatarion in your UserControl.

WPF pre-render a list w/o actually showing it

Is there a way to "pre-render" a list in WPF without actually showing it to the user? I have a list that renders fairly slowly ( a few seconds ) the first time it is displayed to the user.
I'd like to pre-render/pre-draw the list so that the few seconds it takes to display the list to the users is not noticeable. I'd like this to happen while the app is starting up - while my splash screen is displayed.
What is the best way to accomplish this?
EDIT:
Here is my list item style. As you can see the target type is a Button. The button also has a RoutedEvent (Command) set on it.
<Style x:Key="Button_ProductFinder_Item" TargetType="Button">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Width="690" Height="181" >
<Image Name="Up" Source="{StaticResource Img_ProductFinder_FriendUp}" Stretch="Uniform"/>
<Image Name="Down" Source="{StaticResource Img_ProductFinder_FriendDn}" Visibility="Hidden" Stretch="Uniform"/>
<Canvas Name="Clip" ClipToBounds="True" Height="162" Width="175" HorizontalAlignment="Left" Margin="0,10,0,0" >
<Image Name="DynamicFriend" Stretch="UniformToFill" Canvas.Left="16" Canvas.Top="-10" HorizontalAlignment="Left" Source="{Binding ImageSource}" Height="162" Width="162" />
<Canvas.RenderTransform>
<TransformGroup>
<TranslateTransform />
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
<TextBlock Name="DynamicName" Margin="210,69,0,0" Style="{StaticResource ButtonFriend_Textstyle}"
TextWrapping="Wrap" HorizontalAlignment="Left" Width="440" VerticalAlignment="Stretch" Height="Auto"
Text="{Binding ProductName}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Up" Property="Visibility" Value="Hidden"/>
<Setter TargetName="Down" Property="Visibility" Value="Visible"/>
<Setter TargetName="Clip" Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<TranslateTransform Y="2"/>
</TransformGroup>
</Setter.Value>
</Setter>
<Setter TargetName="DynamicName" Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<TranslateTransform Y="2"/>
</TransformGroup>
</Setter.Value>
</Setter>
<Setter TargetName="DynamicName" Property="Foreground" Value="#FFFFFF"/>
<Trigger.EnterActions>
<ctrls:ButtonSoundPlayerAction SoundFile="buttonclick.wav"/>
</Trigger.EnterActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Check WHAT is slow. Really. Itf it is like the db filling up the list, your question is totally off (as the perforamnce is not WPF realted).
How large is the list? I have a list of 5000 elements rendering in a moments notice. Mosty because my 4.0 virtual list only renders what is on the list. You are not data bound while fillng up the list, or?
Finally, what is slow in the rndering? Use a wpf profiler to find out and tell us - because at the nd of the day you may simply try to optimize the wrong thing.
You could always set the list (or the whole window the list is contained in) to collapsed in it's initial state, and then un-collapse it when you get word back from your data retrieval thread that it is done.
I have done that with a couple of my other programs and it works pretty well.
User executes the program, splash screen displays, and main window loads collapsed.
Data retrieval thread executes, gets data, reports it is finished.
Splash screen disappears, main window displays and list is populated.

Resources