Get the children of the object present - c#

I'm having a Grid and in that grid m having a scroll-able content and in that having a chartgrid
Xaml Code
<TabItem x:Name="Charts" Header=" Company Charts " TabIndex="0" IsSelected="True">
<ScrollViewer x:Name="ScrollViewerDN" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" Background="Transparent" telerik:StyleManager.Theme="Expression_Dark">
<Grid Name="OuterGridChart">
<Grid x:Name="ChartGrid" Margin="10" Background="Transparent" >
CS CODE
private void ExecuteExportSingleChartToPdf(object obj)
{
var values = ((System.Collections.Generic.List<object>)(obj)).ToList();
Grid grid1 = values[0] as Grid;
above ExecuteExportSingleChartToPdf is a delegate command for a button
I'm able to generate a image temporarily bt the issue is that only the current selected tab is generated as image
Wanna to have both the grid-> children (tabcontrol) -> grid
access the children
And the chart grid (tabcontrol) ..charts are displayed in row and coloumn, want to have the row wise image to be saved as one.

You can create an image from any Visual element (virtually all controls extend the Visual class) using just a few lines of code. Rather than repeat myself again, please refer to my answer to the How to take a screenshot of a WPF control? question to find out how to do that.
Now all you need to do is to rearrange your XAML so that you have all of your row controls in one control. Therefore, I would recommend that you define a new Grid control with however many columns that you need in your relevant Grid row... you can use the Grid.IsSharedSizeScope Attached Property to align the new Grid columns with any outer columns if need be.
Finally, just pass a reference to your new Grid to the code from the linked question and you will have an Image of your controls.

Related

Make user control added as child fill stackPanel

my main window consists of a Grid splitting it into two parts.
in one of the parts i have a stackPanel.
into the stackPanel i add via stackPanel.child.add(user control) (from the .cs file) the selected user control window
my question is: how do i make this one child added via the .cs fill the stackPanel completely?
Xaml code:
<StackPanel Name="myStkP" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" DockPanel.Dock="Bottom"/>
.cs code:
firstAttempt fat = new firstAttempt();
this.myStkP.Children.Add(fat);
firstAttempt is the user control (wpf) i created
The child element, fat, should also have VerticalAlignment="Stretch" HorizontalAlignment="Stretch"

WPF: Accessing grid defined under Data Template which inturn is defined under Resource dictionary in C#

Inputs: I have a theme xaml file where in all the data templates are defined for specific datatypes. Refer below, I have a data template of type Table consisting of grid. The data template is defined under resource dictionary. I have kept Grid empty and just given name as DynamicGrid. The grid content willbe decided by me at run time and so I have kept it empty. ( example the grid can be 2 by 2 table with each cell as textbox and some textbox can span till any row or any column).
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:th="clr-namespace:ThemeDataModel"
xmlns:my="clr-namespace:ThemeEditor"
xmlns:utility="clr-namespace:Utility.Wpf;assembly=Utility"
xmlns:wa="clr-namespace:WorkAreaControl;assembly=WorkAreaControl"
xmlns:p="clr-namespace:ThemeEditor.Properties"
>
<DataTemplate x:Name="temData" DataType="{x:Type th:Table}">
<Grid x:Name="DynamicGrid">
</Grid>
</DataTemplate>
...
Question: My quesion is how do i access the grid ( name as DynamicGrid ) from the C# code behind. So my workflow is, whenever an object of type "Table" is added in my themearea then it should use the above datatemplate and I should be able to access the grid under the data template and fill it dynamically. I am new to WPF so kindly suggest. If I hardcode and define the grid content in xaml file itself I am able to get the table but I want to do it dynamically.
Then how can I accomplish this ? When my object of type Table is added i need that grid to be display inside a dragresize control which is already there. for example. refer below wokring example. When object of type "AnotherTable" is added it adds a grid with tooltip and a textblock with white backgroud in it.
<DataTemplate DataType="{x:Type th:AnotherTable}">
<Grid ToolTip="{DynamicResource AreaTip}">
<TextBlock Text="{DynamicResource Text}" Background="White"></TextBlock>
</Grid>
</DataTemplate>
My requirement is I dont know how the grid will look like and it has to be decided at run time.

Get item's object for the dropped gridview Grid

I have a GridView with a custom template. I want the user to be able to drop some of items on another items. I enabled the drag & drop and added the drop handler to the Grid which is used for item's template:
<GridView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Left" Width="250" Height="250" AllowDrop="True" Drop="content_Drop">
With the code above, I'm able to handle which Grid the user has dropped the item onto. However, I'm not able to get the object for this Grid. A trick (using an invisible control and lookup) comes to my mind but I'm looking for a better way.
The DataContext property of the Grid will be set to the item bound to that ItemTemplate.

Grid inside a scrollviewer with multiple user controls inside

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.

Thumbnail Control

Hi all i need to design a control that has a thumbnail views of picture.it can take list of pictures.i need it in wpf.is there any pre existed library of control?
if no how can i design i have no idea
Thanks
was looking something like http://www.codeproject.com/KB/graphics/crystal_image_grid_viewer.aspx?msg=3290254
If you have a list of pictures you can place a panel (StackPanel, WrapPanel, etc., depends on the behaviour you want) inside a ListBox. Set the panel to be the items host, and set the list of pictures as the ItemsSource. Something like this:
<ListBox x:Name="_listBox" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" IsItemsHost="true" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
and then in the code behind set _listBox.ItemsSource to your list of pictures.
(or you can have your list of pictures in an ObservableCollection and bind the ListBox to it)
EDIT: as for the thumbnails you can use something like:
BitmapImage Picture = new BitmapImage();
Picture.BeginInit();
Picture.UriSource = ... // your picture
Picture.DecodePixelWidth = ... //how big you want your pic
Picture.EndInit();
do you want to show all the images of the list at the same time? I believe you can use the grid and put a picture control in any cell of the grid, you can start with this approach, post your results and ask more specific questions once you have it at least partly done.

Categories

Resources