I am programmatically creating a popup for an element in a WPF window and can't get rid of the black border:
var p = new Popup {
PlacementTarget = target,
IsOpen = true,
StaysOpen = false,
AllowsTransparency = true
};
// Add the popup content
p.Child = new Views.MapLocationInformation {DataContext = context};
The User control MapLocationInformation is defined in XAML like this:
<UserControl ...
mc:Ignorable="d"
Background="Transparent"
d:DesignHeight="65" d:DesignWidth="401">
<Border BorderThickness="1"
CornerRadius="5"
BorderBrush="{StaticResource ExpanderHeaderBorderGradient}"
Background="White"
Margin="0 0 8 8">
<Stackpanel> ... </Stackpanel>
</Border>
</UserControl>
I cannot find any combination of border, background fill and transparency setting which would render the black area transparent. Any idea?
Your Popup allows transparency but is not using a transparent background. Change to:
var p = new Popup {
PlacementTarget = target,
IsOpen = true,
StaysOpen = false,
AllowsTransparency = true,
Background = Brushes.Transparent
};
That should do the trick. Also, the reason the black bit is wider on the right and bottom is due to the Margin on your Border, which is actually kind of useless. I suggest you remove that too.
I just ran into the same problem. The problem appers to be, that when the Popup's IsOpen Property is to True too early, the transparency is not working properly.
My Solution was to move setting IsOpen to true from the contruction to the Loaded event of the Popup.
myPopup.Loaded += (sender, args) => { myPopup.IsOpen = true; };
This is caused by the Background property of MapLocationInformation. Just set the Background of your UserControl to null and AllowsTransparency to True to fix it, like this:
<UserControl ...
mc:Ignorable="d"
Background="{x:Null}"
AllowsTransparency="True"
#NikoR is right. But it is just the order of the properties.
You must set AllowsTransparency before IsOpen:
var popup = new Popup
{
AllowsTransparency = true,
IsOpen = true
};
In my case all I needed to add was AllowsTransparency = true for the Popup. I have a feeling Kent's answer is correct, and the inclusion of a nonexistent Background property there is not relevant because it is not needed.
Related
"I have two or more dockingManager, and I want every FloatingWindows to be dockable on every dockingManager."
floatingWindows must be created within a dockingManager, but it must be possible to dock it into another separate docking manager.
so when I do drag inside the first dockingManager the default positions are displayed. (4 icons: top, left, bottom, right)
but when I drag the floatingWindows into the second dockingManager nothing appears.
<Grid>
<avalonDock:DockingManager x:Name="dock1" Width="300" Height="200">
<avalonDockLayout:LayoutRoot>
<avalonDockLayout:LayoutRoot.FloatingWindows>
<avalonDockLayout:LayoutAnchorableFloatingWindow>
<avalonDockLayout:LayoutAnchorablePaneGroup DockHeight="100" DockWidth="100">
<avalonDockLayout:LayoutAnchorablePane x:Name="_LayoutAnchorablePane" FloatingHeight="150" FloatingWidth="150">
<avalonDockLayout:LayoutAnchorableTitle="FloatingWindow">
<Grid Background="CornflowerBlue">
</Grid>
</avalonDockLayout:LayoutAnchorable>
</avalonDockLayout:LayoutAnchorablePane>
</avalonDockLayout:LayoutAnchorablePaneGroup>
</avalonDockLayout:LayoutAnchorableFloatingWindow>
</avalonDockLayout:LayoutRoot.FloatingWindows>
</avalonDockLayout:LayoutRoot>
</avalonDock:DockingManager>
<avalonDock:DockingManager x:Name="dock2" Width="300" Height="200" >
<avalonDockLayout:LayoutRoot>
</avalonDockLayout:LayoutRoot>
</avalonDock:DockingManager/>
I also tried to force it from code, but it does not work!
LayoutAnchorable mAnchorableChilder=null;
public MainWindow()
{
InitializeComponent();
mAnchorableChilder = new LayoutAnchorable();
mAnchorableChilder.Title = "Sample dynamic avalondock";
_LayoutAnchorablePane.Children.Add(mAnchorableChilder);
Grid grid = new Grid { Background = new SolidColorBrush(Colors.Green) };
mAnchorableChilder.Content = grid;
}
I'm using a ComboBox with property IsEditable=true created using the following code:
ComboBox buffer = new ComboBox()
{
BorderBrush = null,
Foreground = new SolidColorBrush(Colors.Black),
Background = null,
FontFamily = new FontFamily("Segoe UI Semilight"),
FontSize = 24,
IsEditable = true,
IsTextSearchEnabled = true,
IsTextSearchCaseSensitive = false,
StaysOpenOnEdit = true,
};
It is added in a WrapPanel in a ScrollViewer defined like this :
<ScrollViewer Margin="582,107,142,240"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Height="226" Width="357">
<Border Background="White"
CornerRadius="10"
BorderBrush="Black"
BorderThickness="1"
MouseDown="Border_MouseDown"
MouseLeave="Border_MouseLeave"
MouseUp="Border_MouseUp">
<WrapPanel x:Name="sourcesWrapPanel" Width="357"/>
</Border>
</ScrollViewer>
It works fine when selecting manually but writing will not work (pressing the keys does not input any text). The only thing that works is selecting an item using the mouse or the up/down arrows then deleting characters in it using backspace. What am I missing?
Take a look at the documentation for ComboBox.IsEditable:
I think you need to set ComboBox.IsReadOnly to false.
The e.Handled was set to true in the parent control so only the PreviewKeyDownhandler was executed for the child (ComboBox) which is why I could only delete text or paste it but not write any.
How to achieve an automatic full screen that not hides the taskbar, with no resize and no window style?
I tried to use the following code, but it doesn't work right, as shown in the image below.
XAML:
<Window x:Class="WPF_Test_Environment.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowState="Maximized" ResizeMode="NoResize" WindowStyle="None">
<DockPanel>
<Button DockPanel.Dock="Top" Height="50">Top</Button>
<Button DockPanel.Dock="Bottom" Height="50">Bottom</Button>
<Button DockPanel.Dock="Left" Width="50">Left</Button>
<Button DockPanel.Dock="Right" Width="50">Right</Button>
<Button Width="50" Height="50">Center</Button>
</DockPanel>
</Window>
Code-Behind:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
MinHeight = SystemParameters.MaximizedPrimaryScreenHeight;
MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
MinWidth = SystemParameters.MaximizedPrimaryScreenWidth;
}
}
Here is the result:
As you can see, the "Bottom" button is partially underneath the taskbar, and I want it to be entirely above it. So, ideally, it would look as shown in the following image, but without the border on the top:
It can be done with calls to unmanaged code. Check this article to see how to do it. Basically, just remove your width and height settings from code-behind, implement the WindowSizing class from the article and call it from SourceInitialized event of the window.
Edit
The other solution would be to add reference to Windows Forms and use:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// Set the width and height values to the values of working area
this.Width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
this.Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
// Move the window to top left corner of the screen
this.Left = 0;
this.Top = 0;
}
Just make sure to remove WindowState="Maximized" from your window.
Not sure if any of these is elegant though.
First, let me state my intentions. This is the final result I am looking for.
Mockup Of Intent http://s18.postimg.org/x818zbfbb/image.png
The output of my code, however, fails to achieve this. Here's what I did. This is my MainWindow XAML.
<Window x:Class="App.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="" Height="200" Width="400"
WindowStartupLocation="CenterScreen" Name="ViewData">
<Grid Name="splMain" Background="{StaticResource GreyGradient}"></Grid>
</Window>
And this is the C# code for the dynamic RowDefitions creation:
private void ViewImgData(SubPod subPod)
{
var wb = new WebBrowser();
wb.Navigate(subPod.Image.Src);
var rowDefinition = new RowDefinition();
rowDefinition.Height = GridLength.Auto;
splMain.RowDefinitions.Add(rowDefinition);
Grid.SetRow(wb, 0);
((MainWindow)System.Windows.Application.Current.MainWindow).splMain.Children.Add(wb);
}
This I am calling from over here. It is guaranteed that this foreach loop would run more than once. However, my output window shows only 1 image instead of 2 or more, that too not taking up the whole space of the Window.
foreach (SubPod subPod in pod.SubPods)
{
Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Background,
new Action(() => ViewImgData(subPod)));
}
Where have I mistaken? Thanks.
You add new rows, but place the new webbrowser component in the 0th row.
Try
Grid.SetRow(wb, splMain.RowDefinitions.Count-1);
instead, since you need to place new content in the new row.
EDIT:
To fit the grid height and width try adding this to your splMain grid
Width="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType={x:Type Window}}" Height="{Binding ActualHeight,RelativeSource={RelativeSource AncestorType={x:Type Window}}"
see also Stretch Grid to window size
I have a situation where I need to tab using TabKey from one control to another. The condition is that the focus should never go to control that does not have user inputs so only Text, ComboBox, List DatePicker but somehow the focus after 3 controls get the Focus to go to a dashed line Rectangle (Could be of a Grid, StackPanel, I have not been able to findout) around the control groups before it gets into the control. I have searched very thoroughly in Google and stack over flow for a solution but none seem to work.
Various solutions I tried:
1) Here I set FocusVisualStyle property to null right at start up for Grid and StackPanels. Created a new class:
<StackPanel views:FocusVisualTreeChanger.IsChanged="True" Name="parentStackPanel" Orientation="Vertical" Style="{DynamicResource key1}" FocusVisualStyle="{x:Null}">
public class FocusVisualTreeChanger
{
public static bool GetIsChanged(DependencyObject obj)
{
return (bool)obj.GetValue(IsChangedProperty);
}
public static void SetIsChanged(DependencyObject obj, bool value)
{
obj.SetValue(IsChangedProperty, value);
}
public static readonly DependencyProperty IsChangedProperty =
DependencyProperty.RegisterAttached("IsChanged", typeof(bool), typeof(FocusVisualTreeChanger), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits, IsChangedCallback));
private static void IsChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (true.Equals(e.NewValue))
{
FrameworkContentElement contentElement = d as FrameworkContentElement;
if (contentElement != null)
{
contentElement.FocusVisualStyle = null;
return;
}
FrameworkElement element = d as FrameworkElement;
if (element != null)
{
element.FocusVisualStyle = null;
}
}
}
}
Did not work.
I tried setting FocusVisualStyle property to null for only Grid and StackPanel seems to go through the codebehind if I put a break point but the focus rectangle does not go away:
<Grid Name="AppointmentGrid" Style="{DynamicResource key2}" FocusVisualStyle="{x:Null}">
Style style = new Style { TargetType = typeof(Grid) };
style.Setters.Add(new Setter(Grid.FocusVisualStyleProperty, null));
style.Setters.Add(new Setter(Grid.FocusableProperty, false));
Application.Current.Resources["key2"] = style;
Application.Current.Resources["key3"] = style;
Application.Current.Resources["key4"] = style;
Style style1 = new Style { TargetType = typeof(StackPanel) };
style1.Setters.Add(new Setter(StackPanel.FocusVisualStyleProperty, null));
style1.Setters.Add(new Setter(StackPanel.FocusableProperty, false));
Application.Current.Resources["key1"] = style1;
Can anyone please help me out with a solution that I have not already tried. None in stackoverflow solutions seem to work. I also set Focusable=false just incase but that doesn't seem to help either.
I also read:
Remove focus rectangle on a UserControl
WPF Control remove focus and hover effect (FocusVisualStyle?!)
WPF: Remove dotted border around focused item in styled listbox
This is what I think I am stuck at. A comment I found in one of the search sites.
That's a great way to change the default value of a DP, but it will not help in situations where a control's style explicitly changes the property value. Unfortunately, FocusVisualStyle is one such property. More specifically, styles for controls like Button, ComboBox, ListBox, etc. tend to explicitly contain a Setter for the FocusVisualStyle property. This setter will override the default value that you establish by overriding the metadata.
Can someone suggest a solution that will work in my case. I have a User control
<UserControl
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:csla="http://schemas.lhotka.net/4.2.0/xaml"
xmlns:input="clr-
FocusVisualStyle="{x:Null}"
Focusable="False"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
mc:Ignorable="d" d:DesignWidth="948"
IsTabStop="False"
TabIndex="-1">
<StackPanel views:FocusVisualTreeChanger.IsChanged="True" Name="parentStackPanel" Orientation="Vertical" Style="{DynamicResource key1}" FocusVisualStyle="{x:Null}"><Grid Name="AppointmentGrid" Style="{DynamicResource key2}" FocusVisualStyle="{x:Null}">
Thanks
Dhiren