I have a TabControl,inside one Tabitem, i have a grid and my userControl inside the grid:
<TabControl>
<TabItem>
<Grid HorizontalAlignment="Left" Height="64" Margin="288,150,0,0" VerticalAlignment="Top" Width="354">
<Canvas>
<local:MyCustomComboBox x:Name="ucc1" HorizontalAlignment="Left" Grid.RowSpan="2" Grid.ColumnSpan="3" Height="30" VerticalAlignment="Top" Width="194" ClipToBounds="True"/>
<Canvas>
</Grid>
<TabItem>
<TabControl>
By default,when the userControl's size is greater than the grid's/TabItem's size,the extra portion can't be seen.How can i make my UserControl overlap it ? I tried to add RowSpan and ColumnSpan but it didn't work :(
TabItem has it's own bounds which u cannot overlap.So,there's no way u can achieve your goal ... But i always try my best to help people, so here's a quick tip :
If the usercontrol is bigger than the gird
Your userControl XAML includes MyCustomComboBox, which makes me think it is a combobox..I've seen your previous post where you wanted to customize your combobox but couldn't quite achieve your goals...So, are you trying to create you own custom combobox and by usercontrol bigger than the grid , did u mean that the drop down menu u created doesn't go outside the grid rather is clipped to the grid ??
If this is the case , u can use a ContextMenu and move your custom drop-down list there.Then the contextMenu will overlap both the TabItem and Grid as it is a window itself.
Also , NOTE that u cannot use Named content in usercontrol(u can but that requires a workaround).So i suggest you to add all required code behinds , even set required binding from the user-control's code behind.
Hope this helps :)
Related
I'm trying to get a fresh little reactUI WPF app up and running. However ViewModelViewHost causes me problems. It does not fill the widow but stays at its minimum required measures. (as calculated off of its children)
I have this bit of XAML in my MainWindow.xaml:
<Grid Grid.Row="1" Name="WorkArea">
<reactiveUi:ViewModelViewHost ViewModel="{Binding .}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0" DataContext="{Binding DocVm}">
<reactiveUi:ViewModelViewHost.DefaultContent>
<Label Content="no file" FontStyle="Italic" FontSize="33" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</reactiveUi:ViewModelViewHost.DefaultContent>
</reactiveUi:ViewModelViewHost>
</Grid>
So there is a grid in the MainWindow and the middle part shall be occupied by the ViewModelViewHost hence applying Horizontal and VerticalAlignment. I also tired getting rid of the second grid, but no difference. What actually happens (as seen in Snoop) is: The ViewModelViewHost complies to the stretch setting but its templated part PART_CurrentContentPresentationSite does not comply. It stays at Left + Top. What should I do, how was this intended?
Replace the template...
BTW. It also seems not to be enough just to set the ViewModel-property in order to have the view binding at the view model. You also have to set the DataContext.
You need to use the HorizontalContentAlignment and VerticalContentAlignment and set those to stretch.
I have a XAML ListBox where I am implementing an Image beside that a block of text is there. I want to display a count text in that image. For example for the first block in the image I want to display 1, for the 2nd block I want to display 2. This goes on. Below is the snippet. Can anybody please help me how can I write the count numbers in the image?
<StackPanel Grid.Column="0">
<Image Source="/Assets/Images/pin.png"></Image>
</StackPanel>
<TextBlock Name="locationID" Visibility="Collapsed" ></TextBlock>
</StackPanel>
</StackPanel>
If what you wanna do is display the index of each item of your datasource in your view, there are a couple of ways to do this.
You can save the item's index on a property of the datasource itself and bind that value in your view. This is probably the simplest solution if your collection is static. Cumbersome if dynamic, you would need to manually update the indexes of your collection changes.
You could expose the collection in the app level (making it global), write a converter and provide the item of the collection to it. Then you could search and return the index of that item in your global datasource.
You could implement a multibinding with the Cimbalino Toolkit providing both the item and the datasource and return the index.
here you go
<Grid Grid.Column="0">
<Grid.Background>
<ImageBrush ImageSource="/Assets/Images/pin.png"/>
</Grid.Background>
<TextBlock Text="text on image" Name="locationID" />
</Grid>
whole idea is to place the image as background of grid and place the text as content of the grid.
I have a panorama control in which I have create a header template to add a list picker inside it. (Just like the peoples hub to select social accounts)
<DataTemplate x:Key="PanoramaItemHeaderTemplate">
<ContentPresenter>
<StackPanel Height="129">
<TextBlock Text="{Binding}" FontSize="72" Margin="0,7,0,0" />
<toolkit:ListPicker x:Name="listPick" Margin="0,-21,0,0" BorderThickness="0">
<toolkit:ListPickerItem Content="twitter"></toolkit:ListPickerItem>
</toolkit:ListPicker>
</StackPanel>
</ContentPresenter>
</DataTemplate>
The panorama control is inside the MainPage.xaml file and I want to have access to the listpicker from the code behind to be able to populate it, and handle it selection events.
I don't know how to do this. I tried adding the x:name property to the list picker I don't have access to it in the MainPage code behind.
Any idea on how to approach this is very welcomed, thanks!
From what you have now, the quickest way to do what you want is to traverse the visual tree
See here for the implementation:
How to access a specific item in a Listbox with DataTemplate?
You cannot access the ListPicker by x:Name because it is not unambiguous: there is a ListPicker generated for each PanoramaItem in your Panorama. So the first question is, is it really the think you want to do? If so you need to populate it using a binding (ItemSource)
You can access an element inside another resource, consider this example:
<Grid Name="myGrid">
<StackPanel x:Name="stack1">
<TextBlock x:Name="abc"/>
</StackPanel>
</Grid>
We can only access the Grid myGrid in code by default. To get reference to the StackPanel we can do this:
StackPanel myStack=myGrid.FindName("stack1") as Stackpanel;
After that we can get reference to the TextBlock:
TextBlock myTextBlock=myStack.FindName("abc") as TextBlock;
You can modify myTextBlock after that as you may like. You can apply the same technique in your case and it will work.
Hope that helps :).
I am new to WPF and xaml and I have a problem with my apps UI.
I am using this xaml code:
<ScrollViewer HorizontalAlignment="Left" Margin="252,12,0,0" Name="captchaControlsScrollableContainer" VerticalAlignment="Top">
<Grid Name="captchaControls" Width="339" Height="286">
</Grid>
</ScrollViewer>
And this code behind code that populates the grid:
captchaControls.Children.Add(new Captcha(data));
which is called more than one time
My problem is that only the first user control app apperas in the grid although in the debugger captchaControls.Children.Count is the right size and the scrollviewer's scrollbar is disabled.
Does anyone have any idea what I am doing wrong? Thank you in advance.
Your Grid in the scrollviewer is set to have 1 column and 1 row.So you will see only the last one you add so far (all others controls are "below" the last).
Take a look to the StackPanel control and maybe this tutorial will be useful.
I need to a collection of groupboxes varying on the user selection. for example; there will be 7 groupboxes, the user can enable however many they want and in what order they want. So i want the selected groupbox B to appear at the bottom of the previously selected groupbox A yet when A is unselected B moves up the form to where A was.
In my mind i want it to behave similar to HTML items.
This will be done in WPF, coding in C#.
You can stack these groupboxes in a stackpanel with orientation=vertical. You can then set the Visibility of the groupboxex to the users decision and wpf will make the rest for you "by magic".
Little sample here:
<StackPanel Orientation="Vertical">
<GroupBox x:Name="First" Visibility="Visible" Header="First">
<Label>First</Label>
</GroupBox>
<GroupBox x:Name="Second" Visibility="Collapsed" Header="Second">
<Label>Second</Label>
</GroupBox>
<GroupBox x:Name="Third" Visibility="Visible" Header="Third">
<Label>Third</Label>
</GroupBox>
</StackPanel>
Put your GroupBoxes in a collection of some kind and databind that collection to a cusomised ListView. Whenever the selected state of a GroupBox changes update the view of that ListView to sort them based on your requirements. Unfortunately I am not good enough to provide a working sample in the time I have, sry.