in our WPF application we have and Listbox with a few items. We temporary need to hide some of the items but since we need to keep the item order we don't remove them. We just set the visibility to collapsed.
This works fine so far but the ScrollViewer of the ListView does not refresh. It is still as long as before and shows some very strange behavior when you try to scroll.
Is there any way to refresh the ScrollViewer when items are collapsed? Or any other was to archive what we have done? Removing the items from the ListView is not an option.
Have you set the ItemContainerStyle? Just like:
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Visibility" Value="{Binding Visibility}" />
</Style>
</ListBox.ItemContainerStyle>
Related
I want to achieve layout simmilar to Groove application, where hamburger menu is on the left and appbar on the bottom. However, not all pages contains appbar.
I have an usercontrol called MainFrame which contains the hamburger menu and a navigation frame.
When page is loaded into the navigation frame, the AppBar overlays the HamburgerMenu. I could just offset the HamburgerMenu, but not all pages contains the AppBar, or the AppBar's height is different.
Is it possible to show the hamburger on top of appbar? Or do you have any other ideas?
Use CommandBar instead of Page.BottomAppBar. Also, it is the recommended way for UWP by Microsoft.
You should use the AppBar only when you are upgrading a Universal
Windows 8 app that uses the AppBar, and need to minimize changes. For
new apps in Windows 10, we recommend using the CommandBar control
instead.
Set the CommandBar in the content Grid of HamburgerMenu
Here is a sample code:
<controls:HamburgerMenu>
<!-- Items -->
<controls:HamburgerMenu.ItemsSource>
</controls:HamburgerMenu.ItemsSource>
<!-- Options -->
<controls:HamburgerMenu.OptionsItemsSource>
</controls:HamburgerMenu.OptionsItemsSource>
<!-- Content -->
<Grid x:Name="ContentGrid">
<Frame Name="MainFrame"/>
<CommandBar VerticalAlignment="Bottom"/>
</Grid>
</controls:HamburgerMenu>
I wants to create a form in a specified format where main window area will have some common links or buttons to all pages and the page area is where all the pages will be shown. Is this possible in wpf ?
Yes you can do that by using tab item and frames. You can have an idea using:
<TabItem Header="about" Name="aboutTab">
<TabControl>
<TabItem Header="REGISTRATION" Name="subTabRegistration">
<Grid>
<Frame NavigationUIVisibility="Hidden" VerticalAlignment="Top" HorizontalContentAlignment="Stretch" ClipToBounds="True" JournalOwnership="Automatic" Source="Pages/register-activate.xaml" x:Name="frameRegistration" />
</Grid>
</TabItem>
</TabControl>
</TabItem>
I want to disply all my elipse in the same point using itemControl wpf. by default itemsControl use vertical stackpanel. there's a way to simply remove the StackPanel?
Thanks
Sure, you can give a custom ItemsPanel by either set one in your ItemsControl ControlTemplate, and using the IsItemsHost property to tell which of the panels is the receiver of the items.
<ItemsControl.Template>
<ControlTemplate>
<Canvas IsItemsHost="True"/>
</ControlTemplate>
</ItemsControl.Template>
or by supplying a custom ItemsPanel and telling the position in the template by an ItemsPresenter.
<ItemsControl.Template>
<ControlTemplate>
<ItemsPresenter/>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
WPF 3.5
I have a ListView for which the XAML looks like so
<ListView Name="ListView_FileAttachments">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Type"></GridViewColumn>
<GridViewColumn Header="File Name"></GridViewColumn>
<GridViewColumn Header="Security">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="Set Restrictions" Click="Restrictions_Clicked"></Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
When I Click on a button in an individual cell how do I tell which button was clicked ( to be clear though I am interested in the ListView Item that this button belongs to because what I really want to do is retrieve the value of another column in that row )
The DataContext of the button (i.e. the sender for the event) will be the dataitem from the listview's Items. If you want the container (i.e. the ListViewItem) then you can either walk up the visual tree (e.g. using VisualTreeHelper.GetParent) until you hit the ListViewItem or you can use the ListView_FileAttachments.ItemContainerGenerator.ContainerFromItem passing in the data item (which you get from the DataContext of the button).
I'm hoping to create a control that I call an "AutoCompleteListBox". If you've ever used hotmail to send an e-mail the way the to: address line works is what I wish to create. You have what looks like an input box and as you type you get a dropdown of matching objects. Once you select an object (contact) it is added into the input box as a rectangular object. Multiple objects can be added this way and the input box acts like a wrap panel. You can delete objects by backspacing them or clicking the x button on each.
My approach was to begin by subclassing ItemsControl. I've started to write its control template which is basically a wrap panel that I want to show the bound items + a text box. I don't know how to get both the bound items and the textbox to be in the same wrap panel. Here's what I have:
<Style TargetType="ctrl:AutoCompleteListBox">
<Setter Property="Width" Value="200"/>
<Setter Property="Height" Value="100"/>
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ctrl:AutoCompleteListBox">
<ScrollViewer x:Name="RootScrollViewer" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Padding="0" Background="{TemplateBinding Background}">
<toolkit:WrapPanel IsItemsHost="True">
<!--Items Bound To ItemSource Go Here-->
<TextBox x:Name="txtInput"/>
</toolkit:WrapPanel>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I don't know how to express what I want. I know you can use an "ItemsPresenter" in the control template which does show the bound items but then how can I add my textbox into the same panel as the bound items?
I'd greatly appreciate any help. Is this the right way to even go about it? Thanks very much.
Subclassing the items control is a good start, but I think the controltemplate should be setup a bit different. The Silverlight toolkit contains an excellent autocomplete box that you can use for this exact purpose. Combine this with a separate items control and you should have something that can be styled to look exactly like the live mail "To" field.
<ControlTemplate>
<toolkit:WrapPanel>
<ItemsControl ItemsSource="{TemplateBinding Items}">
<ItemsControl.ItemsPanel>
<StackPanel Orientation="Horizontal"/>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<!-- Add data template for the previously added items here -->
</ItemsControl.ItemTemplate>
</ItemsControl>
<toolkit:AutoCompleteBox ItemsSource="{TemplateBinding AutoCompleteItems}" />
</toolkit:WrapPanel>
</ControlTemplate>