I have the following snippet:
<StackPanel>
<Popup>
<TextBox ToolTip="Edit current date"/>
</Popup>
<Label "Current Date"/>
</StackPanel>
I want the popup to show when the StackPanel is clicked, and hidden when it (the Popup) loses focus.
I was wondering what would be the shortest way to write this in xaml.
To do this with an animation, use BooleanAnimationUsingKeyFrames. The example shows how to animate the IsEnabled property but will work equally well with Popup.IsOpen. (You'll need to scroll waaaay down to see the XAML example.) Take care about the FillBehavior so that the Popup doesn't animate back to being closed when the animation ends (unless of course this is what you want!).
Related
We were able to understand if ItemsControl finished it's rendering by checking Status within StatusChanged event in WPF.
How can I make sure that ItemsControl finished rendering in UWP? I want to make sure that rendering is completed and access some elements using ContainerFromItem.
I have custom dragging logic using events like ManipulationDelta. After rendering, I want to get the ContentPresenter's position based on it's parent UIElement and then use that position to draw some stuff using Win2D. I need item's position, so I need the container, so I need to make sure containers are rendered in the first place, and it goes like that.
To use ItemsControl in UWP, you also need to know about the UI virtualization. The ItemsControl uses UI virtualization. It means that not all items will be rendered at the same time, instead only the viewable area.
You could try the following code:
<ItemsControl x:Name="item">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Loaded="Grid_Loaded">
<TextBlock Text="{Binding}"></TextBlock>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I registered the Loaded event for the 'Grid' which is included in every item.
I am trying to get a RichEditBox to take over the entire width of the app window and to be responsive to window resizing, so far the code I have is the following:
<RichEditBox HorizontalAlignment="Stretch"
TextWrapping="WrapWholeWords"
Height="250"
Name="Intro"/>
What I am getting from the code above is this:
Any ideas on how can I get this to work? Why is it that I tell the text to wrap and it doesn't follow?
UPDATE
I also tried this:
<RichEditBox HorizontalAlignment="Stretch"
Height="250"
Name="Intro"/>
But the result is:
The problem that I am having is that it seems that HorizontalAlignment="Stretch" does not really do anything. The only way I am able to set a decent width is by hard-coding it, for example: Width="600". But if I do this my UI will not respond correctly to resizing. I also tried HorizontalContentAlingment="Stretch" but the result is exactly the same.
How can I get my RichEditBox take up all the available Width and Wrap at the same time?
If you look at the documentation of RichEditBox.TextWrapping, you'll notice that WrapWholeWords is invalid. You have to use
<RichEditBox TextWrapping="Wrap"/>
-or-
<RichEditBox TextWrapping="NoWrap"/>
Since Wrap is the default value, you can drop the property.
<RichEditBox HorizontalAlignment="Stretch"
Height="250"
Name="Intro"/>
Edit: in reply to the updated question:
A control only takes the width of it's parent control. Some container controls (e.g. Grid) automatically take the full width available, while others (e.g. StackPanel) only take the required size of it's children. Using HorizontalAlignment="Stretch" in combination with a StackPanel as a parent control, will only use the MinWidth property instead of the full available width on your screen. Sometimes you can't directly see this issue, e.g. when your control is inside an itemtemplate of a ListView. Use the Live Visual Tree in Visual Studio to find the parent containers and locate the issue.
So in short: make sure your RichEditBox is inside a Grid (or similar control) instead of a StackPanel.
is it possible to get ellipsis inside button when content length increase the width of button.
I tried editing template but did get much success?
You should have some options. If it's just at the instance, you can just plop your content in as TextBlock so something like;
<Button>
<Button.Content>
<TextBlock Text="Blah Blah Blah" TextTrimming="WordEllipsis"/>
</Button.Content>
</Button>
Or if you make a custom style template for Button you could replace the ContentPresenter in it with a TextBlock with it's content bound to the template like Text="{TemplateBinding Content}" and apply your TextTrimming directly to it. Except remember TextTrimming needs a boundary to invoke it, so your Button's may require like a set MaxWidth/Width or its parent panel will have to restrict its size to invoke the trimming.
Hope this helps, Cheers.
PS - This same concept can be used in WP, WPF, Silverlight, whatever really.
I have layout as described below:
<ScrollViewer>
<StackPanel Orientation="Horizontal">
<!-- ... -->
<ScrollViewer>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel ScrollViewer.VerticalScrollBarVisibility="Visible" Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ScrollViewer>
<!-- ... -->
</StackPanel>
</ScrollViewer>
And I would like to achieve that effect that is present in weather app.
In my application, when you're scrolling horizontaly using mouse wheel, when pointer gets over ItemsControl it immediately starts scrolling verticaly wheras in weather application there's fluent horizontal scrolling effect and scrolling verticaly begins when there's some time hover that vertical collection.
Is that behaviour somewhere implemented by default?.
Szymon
Generally, the guideline is that introducing vertical scrolling in a horizontally scrolling repeater is a bad idea. I think you should NOT consider Weather (or any standard Windows 8 app) as a model to emulate. Most of them violate the guidelines in some of the worst ways.
The Weather app accomplishes what you are asking based on the current mouse placement, the motion of the grid, and control with focus. That's a complex way of saying, some developer dreamed up a solution to help make their UI as confusing to the user as possible.
Please, don't.
What I think they do in order to achieve that effect is this:
If the mouse is over the vertical list for a while, they deactivate the horizontal scroll and activate the vertical one. Once the mouse moved outside the list, they switch back (deactivate the vertical scroll and activate the horizontal scroll).
I have not tested this to see if this works, but I think it should.
I'm trying to make a watermark appear inside a TexBox, I have done this with the Canvas tag:
<Canvas Height="60" Width="500" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,5">
<TextBox Width="500" Height="30" Canvas.Left="0" Canvas.Top="0" FontSize="18"></TextBox>
<TextBlock x:Name="whereAreyouWatermark" Canvas.Left="15" Canvas.Top="7" Height="30" FontSize="16"
Foreground="#777777" Width="500">
<Run x:Uid="text2"></Run> <Italic FontSize="13"><Run x:Uid="text3"></Run></Italic>
</TextBlock>
</Canvas>
However, now when the cursor goes over the textblock it's not the "I" icon, just a normal pointer. In CSS, I would change the cursor like this "pointer: text".
How can I do this in XAML?
Also, when pressed I want focus to go to the background textbox, I take it the best way is to just intercept the gotfocus event of the textblock and pass focus in-code to the textbox. I think in iOS you can use a layer which simply passes through events.
thanks very much
Much obliged to ya, as we say all the time in London ;-)
I recommend having a look at the WinRT XAML Toolkit's WatermarkTextBox.
Set the default text to something and once it got focus event, clear the text with whatever the user types. And when it's LostFocus place the watermark again. Your IBeam cursor will not be a problem with this solution.
Simpler solution would be to set some default text (which will serve as a watermark) to the TextBox. On GotFocus event, clear the text from code behind. On LostFocus event, check whether if the user has entered some text or the TextBox is empty. If it has some user text, let it be. If it is empty, place back the watermark text!