In my application, there are logs with levels : Info, Debug, Warning, Error.
I've done a warning counter, with all logs at this level.
I managed to show the counter in a stackpanel with a custom flag.
Actually, all logs are displayed in a tooltip, when the mouse is over the counter.
The issue is that the focus isn't working, so I need to find a component to correct that.
The aim is that the user read all logs, the value of the counter is 0 and the list of logs is empty.
Which component to use to solve my issue ?
I can redefine the parent stackpanel if needed.
you can put a user control in popup control and manipulate the IsOpen property
<Popup x:Name="LoginUiPopup" Placement="Center" IsOpen="True" StaysOpen="True" >
<ContentControl>
<Grid>
</Grid>
</ContentControl>
</Popup>
you can binding IsOpen property with log count.
Related
I have a Popup and a ToggleButton. I set a binding like this:
<ToggleButton x:Name="myToggle" Content="{Binding MyData.Title}" />
<Popup IsOpen="{Binding IsChecked, ElementName=myToggle}" >
<TextBlock Text="{Binding MyData.Details}" />
</Popup>
As you see, I bound the toggle button's content to MyData.Title and the popup's content to MyData.Details.
Now I had the criteria MyData.ShowDetails. If it is true the popup can open and if it is false the popup should not be opened.
How can I set a binding to achieve this?
I tested these bindings on the Popup but no one works:
Visibility="{Binding MyData.ShowDetails, Converter={StaticResource BooleanToVisibilityConverter}}"
IsEnable="{Binding MyData.ShowDetails}"
You could put a panel (Grid ) on top of all the content in your window.
That needs to have a background set but it can be low opacity if you still want to see the window content.
Make that visible only when the popup is shown and collapse otherwise.
Make sure you set focus to your popup when it's shown.
.
Bear in mind.
Popups are separate windows.
They are intended to be shown briefly and have a number of potential drawbacks if you show them for longer periods. EG other applications can appear under them and they don't move with their "parent" window/control.
You might find a modal window is easier and suits better, depending on your exact requirements.
Just instantiate a window and use
PopupWindow newWindow = new PopupWindow();
newWindow.ShowDialog();
Where PopupWindow is just any old window styled to look like you want the popup.
This will guarantee the user can't somehow interact with any other window in your app.
.
Another possibility is to show your "popup" content in a grid which appears on top of everything inside your main window.
That's how editing data works in this:
https://gallery.technet.microsoft.com/scriptcenter/WPF-Entity-Framework-MVVM-78cdc204
The plus or minus of that approach is that it's in the one window.
--- Brian Kress ---
I found a special answer in my case. Instead of disabling Popup, I should disable the ToggleButton:
<ToggleButton x:Name="myToggle" Content="{Binding MyData.Title}"
IsEnabled="{Binding MyData.ShowDetails}"/>
<Popup IsOpen="{Binding IsChecked, ElementName=myToggle}" >
<TextBlock Text="{Binding MyData.Details}" />
</Popup>
It works perfect!
Note: This is not a general answer for Popup. Welcome to anyone who has an answer.
I am currently writing my first user control which would consist of a label and a text box in a stack panel like follows:
<Grid>
<StackPanel Orientation="Horizontal" DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Label Content="{Binding Label}" Width="60"></Label>
<TextBox Text="{Binding TextBoxContent}" Width="60"/>
</StackPanel>
</Grid>
This will be most useful to be in a settings page, as it will be reused for several different settings. With each of these settings, I will want to set (at a minimum) the width, height, validation rule and error template properties. As for the text itself, I have already created a dependency property both for the label and the text box (as you can see in my snippet above).
My question is this: Do I need to create a dependency property for all of the properties I just mentioned that I would like to set when I actually use my user control? This seems like redundant work (since they already exist on the text box, basically they would just redirect my user control's property to the text box's property of the same name)? This is even more work if I want to use even more properties on my text box (for example, AcceptsReturn, etc).
The redundant work can be saved if you decide to derive from TextBox rather than UserControl - just think of your control as a "labeled textbox" and all you need to do is derive from TextBox and add the needed dependency properties to accommodate for the label. This of course would not be the case for more complex user controls, but it seems OK in your case.
The downside to this though is that you'll have to take the default control template for TextBox and work with it to add your label, which may be a bit trickier.
Either way, I recommend having a look at the Control Authoring Overview page on MSDN, which is extremely useful when writing your first controls in WPF.
Introduction
For a project I am working on I had to create a ContentControl which must display a ToolTip/Popup when some provided content is not allowed.
For example:
A TextBox is wrapped inside my ContentControl, the ContentControl provides the logic of displaying a ToolTip when unwanted characters are being typed in the TextBox.
A ToolTip would appear displaying the unwanted characters and after x-period of time, the ToolTip would dissapear.
However using the ToolTip approach led to unexpected and unwanted behavior;
on mouse over an empty tooltip is shown (we could get this to close immediately, but it was still visible for a moment)
when the mouse left the control, the tooltip was hidden
the slide effect could not be controlled precise enough, so depending on the location of the tooltip (above or below) the effect was correct or not.
Therefore I need to have another solution which does not rely on the ToolTip.
Example code
The Xaml structure is like
<ContentControl x:Class="xxx.yyy.zzz.UserControls.MyContentControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
... more namespaces ...>
<ContentControl.Template>
<ControlTemplate TargetType="ContentControl">
<ContentPresenter Content="{TemplateBinding Content}">
<ContentPresenter.ToolTip>
...
And it's usage is like:
<UserControl:Class="xxx.yyy.UserControls.TextBoxControl"
xmlns:cn="clr-namespace:xxx.yyy.zzz.UserControls">
<cn:MyContentControl Info="{Binding ..}" x:Name="MyContentControlName">
<TextBox Text="{Binding Text}" .."/>
</cn:MyContentControl>
Where Info is a dependency property used by my ContentControl's codebehind and for which the input binding is provided by the TextBoxControl's ViewModel.
On a side note:
For our validations we rely on Validation Error Style in WPF, similar to Silverlight and an implementation of How can I move a WPF Popup when its anchor element moves?
I have tried to incorporate some of the template code from the first link mentioned and that resulted only in display a minuscule popup, not displaying anything and neither giving me the behavior I was expecting.
As can be seen in the code snippet, formerly I was using ContentPresenter.ToolTip, unfortunately there is no such thing a ContentPresenter.Popup, whereas I believe a ToolTip is a popup
The question
So how would it be possible to create popup like behavior especially for this piece of code? (this will represent the TextBox on the WPF UI)
<ContentPresenter Content="{TemplateBinding Content}">
Currently I'm working on a WPF project which has defined a custom style for TextBox. Among other things, we override the default control template for the TextBox. The control template looks like this (I've removed a lot of the TemplateBinding stuff since it's not relevant).
<Border>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ScrollViewer x:Name="PART_ContentHost"
IsTabStop="False"
Background="{x:Null}"
VerticalAlignment="Center"
BorderThickness="0"/>
<ContentPresenter Grid.Column="1" Margin="5,0,0,0" Focusable="False"
Content="{TemplateBinding local:UnitConversion.Info}"
ContentTemplateSelector="{DynamicResource SelectorKey}"/>
</Grid>
</Border>
Essentially this just adds a ContentPresenter to display a combo box allowing the user to select different units to be used for display or entry into the text box. The template selector simply selects between the user control (which is really just a ComboBox) or an empty template if the text box doesn't have any associated unit data (the content is null).
The Problem
Since this combo box is essentially part of the text box control template, interacting with the combo box gives keyboard focus to the text box without actually placing the caret into the visual text box. Elsewhere we have a keyboard control which is ultimately made visible when a text box gets keyboard focus (the keyboard itself is actually listening for custom routed events, but these are ultimately raised when a TextBox gets focus.
The Question
Is there any way I can prevent the text box from getting focus when anything other than the actual text entry is what technically got focus? My desired behavior is that manipulating the combo box doesn't result in the on-screen keyboard popping up.
My gut instinct here tells me that I can't actually do what I want since all the focus logic happens at the TextBox level and it doesn't really care much about the contents of the control template. But I'm just curious if anyone might be able to think of some kind of workaround.
I'd like to avoid introducing a custom text box control to handle this since we don't much like the idea of application-specific custom controls (especially considering how far we've gotten with the current one).
On my Window, I have a ViewBox control, which contains a custom progress bar. I set its Visibility to Collapsed in design mode, because I need to display it in only certain moment (during login into app).
In my progress bar, which is usercontrol, I have event handler for VisibilityChanged event where I stop and start my animation.
When user clicks on the Login button, I need to show this ViewBox until Login is completed and collapse it again after success. But, when I (in code behind) set ViewBox.Visibility = Visible, it doesn't show up.
Can anybody tell me why, or how to fix it ?
XAML:
<Viewbox x:Name="cpProgress" Width="50" Height="50" HorizontalAlignment="Center" VerticalAlignment="Bottom" Grid.Row="1" Visibility="Collapsed" >
<lc:CircularProgress />
</Viewbox>
Thanks
change ViewBox.Visibility = Visible to cpProgress.Visibility = Visible and ensure that the Grid has a proper row height defined for row 1.
I've finally come to solution of this problem. It is really simple :).
I've just forgot that If I run the login process in same thread, as my window is in, the UI will hang until the login is completed. So solution is to spawn a new thread,run the login in its context and wait for completed flag to be set in UI's thread. The login process has to be running in asynchronous manner, so the UI could draw my usercontrol.