wpf crystalreport viewer dissappear for no reason - wpf

Well the problem is easy to explain and hard to figure out, at least by me, so i have a tabcontrol with 3 tabitem, on one of the tabitems i have a wpf reportviewer that loads a report of some data, when i change tabs, it does not matter to each one when i get back to the tab with the crystalreport in it, the crystalreport viewer is not there anytmore! i also have a button on top to refresh the report and the button is still there but the crystal report control is not there anymore!
my xaml looks like this
<UserControl x:Class="uccvrFactuur"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:my="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Button Content="Report" Height="50" HorizontalAlignment="Right" Margin="5" Name="Button1" VerticalAlignment="Top" Width="50" />
<my:CrystalReportsViewer Name="crvFactuur" Margin="0,60,0,0" />
</Grid>
</UserControl>
i must say the first time i click on that tab the control is there but i change tabs and go back to it the control is not there anymore.
Thanks in advance

Related

Button Border clipped in WPF with 125% DPI Setting

When I use 125% DPI setting in Windows, sometimes a button border is not rendered. It seems to depend on the size and position, maybe also the parent element of a button:
In my app, I can also see in the WPF designer that a parent border seems to be too small in size, though the button itself is larger. Maybe the measure process is somehow wrong:
I tried changing UseLayoutRounding for the whole window, also changing SnapsToDevicePixels does not help.
DPI Awareness is set in the manifest.
Does anyone know how to fix this for the entire application?
Thats the code in a default Wpf Window Application (I can't reproduce the problem right now, but the problem persists in my application):
<Window x:Class="WpfApp3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow"
SizeToContent="WidthAndHeight">
<StackPanel>
<GroupBox>
<GroupBox.Header>
<Button Width="20"
Height="22"
Content="X" />
</GroupBox.Header>
</GroupBox>
<Button Width="20"
Height="22"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Content="X" />
</StackPanel>
</Window>

Images not appearing on buttons when user control is in referenced assembly

I have a main WPF application which references a WPF User Control Library that I created. In the library, I have one user control and an images folder (images used by user control). Here is part of the XAML that I have in the user control:
<UserControl x:Class="Alstom.UserControls.MainToolbar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Alstom.UserControls"
mc:Ignorable="d"
d:DesignHeight="120" d:DesignWidth="3440">
<UserControl.Resources>
<Image x:Key="Subway" Source="/images/MainToolbar/Subway.png"/>
<Image x:Key="Globe" Source="/images/MainToolbar/Globe.png"/>
<Image x:Key="Gavel" Source="/images/MainToolbar/Gavel.png"/>
<Image x:Key="Clipboard" Source="/images/MainToolbar/Clipboard.png"/>
<Image x:Key="EllipsisVertical" Source="/images/MainToolbar/EllipsisVertical.png"/>
<Image x:Key="Check" Source="/images/MainToolbar/Check.png"/>
<Image x:Key="Bell" Source="/images/MainToolbar/Bell.png"/>
The user control has buttons which I wrote like the following (note that I defined the Content property as StaticResource:
<Button x:Name="button" Grid.Row="1" Grid.Column="0" Content="{StaticResource Subway}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="48" Height="48"/>
When I double click the user control, in the designer, I see the images on the buttons.
But I created a main WPF application in my solution which references the external assembly like so:
<Window x:Class="MainToolBar.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:myMainToolbar="clr-namespace:Alstom.UserControls;assembly=Alstom.UserControls"
mc:Ignorable="d"
Title="MainWindow" Height="auto" Width="3440" ScrollViewer.VerticalScrollBarVisibility="Visible">
<Grid>
<myMainToolbar:MainToolbar HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
When I double-click the MainWindow.xaml, I don't see the images on the button in the designer, nor when I run it.
What do I need to do to show the images at runtime? In the user control project, the images have a Build Action = Resource. But I tried to change one of them to Embedded Resource, and it still did not work.
What am I doing wrong?
Try to set the build action of the images to Resource and use a pack URI:
<Image x:Key="Subway" Source="pack://application:,,,/YourAssemblyName;component/images/MainToolbar/Subway.png"/>
Don't forget to change "YourAssemblyName" to the actual name of your assembly/WPF User Control Library project.
Pack URIs in WPF: https://msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx

Using a properties grid with a tree control

I want to create a tree control that when the user clicks on an element in the tree control, a properties grid is populated with its properties.
I've created a tree control as a user control and I'm using Jaime Oliveras' property grid. I have both on a WPF window but I can't seem to figure out how to make the two communicate with each other.
The XAML on the Main window is:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:advanced="clr-namespace:OptionsStrategyTree.ViewModel"
xmlns:local="clr-namespace:OptionsStrategyTree.ViewModel"
xmlns:Controls="clr-namespace:System.Windows.Controls"
x:Class="OptionsStrategyTree.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="400" Width="500">
<Grid>
<local:UserStrategyTree HorizontalAlignment="Left" Margin="18,6,0,13"
Width="195" Height="340" />
<Controls:WpfPropertyGrid x:Name="StrategyTreePropertyGrid"
HorizontalAlignment="Left" Height="340" Margin="233,6,0,0"
VerticalAlignment="Top" Width="239"/>
</Grid>
</Window>
I've had this properties grid working nicely when the controls are all on the same XAML window. But when I've created a tree control as a user control, it's a separate entity in its own XAML space that seems to be isolated from everything else. Is there any way to connect the two?

Don't understand why the user control we've written doesn't show up in a ModernWindow but does in a window

We're working on a WPF app, using the ModernUI for WPF. And we're also using MVVM Light. We've written some user controls which we intend to bring up in separate windows. Each of the windows are ModernUI's ModernWindow. Whenever we try to bring them up, nothing is shown in the ModernWindow. Out of frustration I thought I'd try doing the same thing in a plain old WPF window. Works perfectly each time. I don't know why it works in a regular WPF window but doesn't work in a ModernWindow. What is wrong???
Here's the XAML for the plain old window:
<Window x:Class="CoreFramework.BozoWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:view="clr-namespace:CoreFramework.View"
xmlns:local="clr-namespace:CoreFramework"
mc:Ignorable="d"
Title="Bozo Window" Height="300" Width="300">
<ContentControl Content="{Binding ProductList, Source={StaticResource Locator}}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
And here's the XAML for the ModernWindow:
<mui:ModernWindow x:Class="CoreFramework.DataViewWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
xmlns:vm="clr-namespace:CoreFramework.ViewModel"
xmlns:view="clr-namespace:CoreFramework.View"
xmlns:content="clr-namespace:CoreFramework"
Title="BOTS"
ShowInTaskbar="True"
Closing="ModernWindow_Closing">
<ContentControl Content="{Binding Path=ProductList, Source={StaticResource Locator}}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
One approach you could use is adding Menu links which is built into the Modern UI framework:
<mui:ModernWindow x:Class="ExampleApp.ExampleWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
Title="Scrum Manager" IsTitleVisible="True" ContentSource="/Views/DefaultUserControl.xaml"
x:Name="mainWindow" MenuLinkGroups="{Binding Groups}"
WindowStartupLocation="CenterScreen" WindowState="Maximized">
<i:Interaction.Triggers>
</i:Interaction.Triggers>
<mui:ModernWindow.TitleLinks>
<mui:Link DisplayName="settings" Source="/Views/SettingsWindow.xaml" />
<mui:Link DisplayName="Sign out" Source="/Infrastructure/Logout.xaml" />
</mui:ModernWindow.TitleLinks>
When a link is clicked, it opens up the 'Source' which would be UserControl xaml files.
See Github for more details:
https://github.com/firstfloorsoftware/mui

WPF: Textblock text in Popup goes outside of the main window

In my example wpf app I've added one button and one popup to the window. The button is in the bottom right corner and the popup has set "PlacementTarget" property to it and "Placement" set to top. The popup consists of one very long textblock.
What I expect this popup will behave is not to go outside of the window and therefore automatically set his "HorizontalOffset" to the appropriate value, but the popup behaves against my intentions.
Here's my xaml file:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1" x:Name="window" x:Class="WpfApplication1.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:Converters x:Key="Converters"/>
</Window.Resources>
<Grid>
<Button x:Name="button" Content="Button" VerticalAlignment="Bottom" Width="75" HorizontalAlignment="Right"/>
<Popup Placement="Top" PlacementTarget="{Binding ElementName=button, Mode=OneWay}" IsOpen="True">
<TextBlock TextWrapping="Wrap" Text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" Background="White"/>
</Popup>
</Grid>
Do anyone know how to fix it?
I've read that this should be default popup behavior to take care of going out of the boundaries, but not in my case. Thanks in advance.
Have you tried to set the width of the Popup or Textblock ?
Sorry, I can't write this poor answer as a comment..

Resources