I want textblock value but could not able to do that - c#

<Grid>
<GroupBox FontSize="16" FontWeight="Bold" Header="Testing"
BorderBrush="Orange" BorderThickness="3">
<DataGrid Background="Transparent">
<DataGrid.Columns>
<DataGridTemplateColumn Width="Auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid IsEnabled="True" Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Hello" Width="50" HorizontalAlignment="Center" VerticalAlignment="Center"
ToolTipService.ToolTip="Testing" Background="Aqua" ToolTipService.IsEnabled="True"
ToolTipService.ShowOnDisabled="True" IsEnabled="True" Height="20" >
</TextBlock>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</GroupBox>
</Grid>
Here is my XAML and this datagrid also comes under groupbox . I have tried many approach but couldnt figure it out . I want to show textblock value.

Related

Why is my DataGrid showing up in the wrong Grid column?

My DataGrid should be showing up in the middle of three Grid columns, Column 1, but instead it appears to be showing up in Column 0, as seen here:
You can see there that my Cancel button (Column 0) and my OK button (column 2) are right next to each other because the DataGrid appears to be occupying Column 0, instead of Column 1. However, when I break my code during execution and do Grid.GetColumn(DataGridFilteredFixesReportsTable), it properly returns 1.
I've also tried moving the DataGrid to Column 2 to see what happens, but the visual result was exactly the same.
What am I doing wrong or misunderstanding about how this works?
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid Margin="20,20,20,20" Name="SettingsGrid" Visibility="Visible">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MaxHeight="600"/>
<RowDefinition Height="40"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<DataGrid Grid.Row="0" Grid.Column="1"
Name="DataGridFilteredFixesReportsTable"
ItemsSource="{Binding Path=FilteredFixesReportsTable.DefaultView}"
DataContext="{Binding ElementName=SeeAllFixesReportsWindow}"
AutoGenerateColumns="True"
FontSize="28" FontFamily="Times New Roman"
IsReadOnly="True">
</DataGrid>
</ScrollViewer>
<Button Grid.Row="2" Grid.Column="0"
Name="ButtonCancel"
Click="OkCancel_Click"
Content="Cancel"
FontSize="32" FontFamily="Times New Roman" FontWeight="Bold" Background="Pink"/>
<Button Grid.Row="2" Grid.Column="2"
Name="ButtonOk"
IsDefault="True"
Click="OkCancel_Click"
Content="OK"
FontSize="32" FontFamily="Times New Roman" FontWeight="Bold" Background="PaleGreen"/>
</Grid>
</ScrollViewer>
Direct children of the Grid should have the column and row specifications. Your DataGrid is a child of ScrollViewer, not Grid so it is ignoring those properties.
Try:
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid Margin="20,20,20,20" Name="SettingsGrid" Visibility="Visible">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MaxHeight="600"/>
<RowDefinition Height="40"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<!-- Should be set here -->
<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="0" Grid.Column="1" HorizontalScrollBarVisibility="Auto">
<DataGrid
Name="DataGridFilteredFixesReportsTable"
ItemsSource="{Binding Path=FilteredFixesReportsTable.DefaultView}"
DataContext="{Binding ElementName=SeeAllFixesReportsWindow}"
AutoGenerateColumns="True"
FontSize="28" FontFamily="Times New Roman"
IsReadOnly="True">
</DataGrid>
</ScrollViewer>
<Button Grid.Row="2" Grid.Column="0"
Name="ButtonCancel"
Click="OkCancel_Click"
Content="Cancel"
FontSize="32" FontFamily="Times New Roman" FontWeight="Bold" Background="Pink"/>
<Button Grid.Row="2" Grid.Column="2"
Name="ButtonOk"
IsDefault="True"
Click="OkCancel_Click"
Content="OK"
FontSize="32" FontFamily="Times New Roman" FontWeight="Bold" Background="PaleGreen"/>
</Grid>
</ScrollViewer>
Since it isn't set on the ScrollViewer it is defaulting to 0 and 0 for row and column.

Grid in Grid not showing Scrollbar in C# WPF

I have a Grid in another Grid and add the second Grid into ScrollViewer but don't see scrollbar for it. The grid i add ScrollViewer has the name InfoGrid. I dont understand why ScrollViewer is not working. Is there any alternative way you can suggest me ? My xaml code for the all window :
<Window x:Class="ModelView.KillCardCheck"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="Auto" Height="Auto" SizeToContent="WidthAndHeight"
ResizeMode="NoResize" Icon="pack://application:,,,/Resources/image/ffdc_gui.png"
xmlns:lex="http://schemas.root-project.org/xaml/presentation" Closing="WindowClosing">
<Grid Style="{DynamicResource GridStyle}" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="12"/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="11"/>
<ColumnDefinition Width="109"/>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<DataGrid Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="2" Style="{DynamicResource {x:Type DataGrid}}"
AutoGenerateColumns="False" CanUserSortColumns="False" CanUserAddRows="False"
Margin="4,4,4,4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RowHeight="25" Name="dgKillCardChecks"
SelectionMode="Single" BorderThickness="1,1,1,0">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Number}"
Width="30" IsReadOnly="True">
</DataGridTextColumn>
<DataGridTemplateColumn Header="{lex:LocText Key=check_list, Dict=language, Assembly=FfdcLocalization}" Width="*" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="chkCheckList" Content="{Binding CheckItem}"
Click="CheckListCheckBoxOnClick"
Tag="{Binding Index}"
IsChecked="{Binding Path=CheckStatus, UpdateSourceTrigger=PropertyChanged}"
IsHitTestVisible="{Binding Enabled}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<ScrollViewer VerticalScrollBarVisibility="Visible">
<Grid Style="{DynamicResource GridStyle}" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3" Margin="4,4,4,4" Name="InfoGrid" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
</ScrollViewer>
<TextBlock Name="descriptionBlock" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Margin="4,4,4,4"></TextBlock>
<Button Style="{DynamicResource {x:Type Button}}" Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="1"
x:Name="btnQuit" MaxHeight="30" Margin="2,4,0,6" MaxWidth="120" MinWidth="80"
Content="{lex:LocText Key=close, Dict=language, Assembly=FfdcLocalization}"
VerticalContentAlignment="Center" MinHeight="30" VerticalAlignment="Center" HorizontalAlignment="Left" Click="CloseClick"/>
<Button Style="{DynamicResource {x:Type Button}}" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2"
x:Name="btnClear" MaxHeight="30" Margin="2,4,0,6" MaxWidth="200" MinWidth="80"
Content="{lex:LocText Key=clear_killcard, Dict=language, Assembly=FfdcLocalization}"
VerticalContentAlignment="Center" MinHeight="30" VerticalAlignment="Center" HorizontalAlignment="Right" Click="ClearKillCardClick"/>
</Grid>
</Window>
The ScrollViewer that you made has no grid.Row set, instead you put it on the grid inside it. That does not make much sense since the grid ("Info Grid") is inside the ScrollViewer so it's parent is the ScrollViewer. You might want to try setting the ScrollViewer row and column.

WPF - Infinite datagrid height

I am using Syncfusion's SfDataGrid instead of standard one, but this question is more about XAML, not the control itself, I think.
So, I have a window with DataGrid. If there is for example 60 records, then the window gets really tall. I want the window not to change its size at all. And really don't know why it's happening.
This is my XAML:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Margin="10,0,10,0" Grid.Row="0" DataContext="{Binding Info}">
<TextBlock Text="Amount:"/>
<sf:CurrencyTextBox Value="{Binding Amount}" Margin="0,0,0,10"/>
<!-- some other controls -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Style="{StaticResource LeftLabel}"
Text="Count:"/>
<sf:UpDown Grid.Column="1" Grid.Row="0" Margin="0,0,0,5"
Value="{Binding Count}"/>
<TextBlock Grid.Column="0" Grid.Row="1" Style="{StaticResource LeftLabel}"
Text="Year count:"/>
<sf:UpDown Grid.Column="1" Grid.Row="1"
Value="{Binding YearCount}"/>
</Grid>
</StackPanel>
<Button Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,10,10,5"
Content="Simulate >>"
Command="{Binding SimulateCommand}"/>
</Grid>
<!-- This is right part of the window with datagrid -->
<DockPanel Grid.Column="1">
<WrapPanel DockPanel.Dock="Top">
<TextBlock Margin="10" Text="Total amount:" />
<TextBlock Text="{Binding TotalAmount"/>
</WrapPanel>
<!-- and the datagrid -->
<sf:SfDataGrid AutoGenerateColumns="False"
AllowDeleting="False"
AllowEditing="False"
IsReadOnly="False"
AllowGrouping="False"
AllowFiltering="False"
ItemsSource="{Binding History}">
<sf:SfDataGrid.Columns>
<sf:GridDateTimeColumn DisplayBinding="{Binding Date}" MappingName="PaymentDay" HeaderText="Date"/>
<sf:GridCurrencyColumn DisplayBinding="{Binding Amount}" MappingName="PayAmount" HeaderText="Amount"/>
</sf:SfDataGrid.Columns>
</sf:SfDataGrid>
</DockPanel>
</Grid>
So what is wrong with it?

how to correct columns and rows that nicely displays datagrid?

I am working on some view in wpf mvvm. I don't know how to fix columns and rows to show correctly my datagrid. I want to have one textbox under name, one textbox under value
Here is a image and xaml code, can anybody help me?
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DataGrid ItemsSource="{Binding EnviromentVariables}" IsReadOnly="False" Margin="10" AutoGenerateColumns="False" Grid.ColumnSpan="4">
<DataGrid.Columns>
<DataGridTextColumn x:Name="name" Width="*" Header="Name" Binding="{Binding Name}" />
<DataGridTextColumn x:Name="value" Width="*" Header="Value" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBox Grid.Row="1" Grid.Column="1" Width="{Binding ElementName =name}" />
<TextBox Grid.Row="1" Grid.Column="3" Width="{Binding ElementName= value}"/>
<Button Content="+" Grid.Column="2" Grid.Row="2" />
<Button Content="-" Grid.Column="3" Grid.Row="2" />
</StackPanel>
</Grid>
Try first of all removing the StackPanel, because, even if you use Grid.Row and Grid.Column properties nothing will effect:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DataGrid ItemsSource="{Binding EnviromentVariables}" IsReadOnly="False" Margin="10" AutoGenerateColumns="False" Grid.ColumnSpan="4">
<DataGrid.Columns>
<DataGridTextColumn x:Name="name" Width="*" Header="Name" Binding="{Binding Name}" />
<DataGridTextColumn x:Name="value" Width="*" Header="Value" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
<TextBox Grid.Row="1" Grid.Column="0" Width="{Binding ElementName =name}" Grid.ColumnSpan="2" Margin="10,0,0,0"/>
<TextBox Grid.Row="1" Grid.Column="2" Width="{Binding ElementName= value}" Grid.ColumnSpan="2" Margin="0,0,10,0"/>
<Button Content="+" Grid.Column="2" Grid.Row="2" />
<Button Content="-" Grid.Column="3" Grid.Row="2" />
</Grid>
Remember to adjust margin of Textboxes.

How to make a grid in a DataTemplate for a ItemTemplate auto-size to ListBox width?

So I have the following DataTemplate for a ListBox.ItemTemplate:
<DataTemplate x:Key="Tweet">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Image
Grid.Column="0"
Source="{Binding ProfileImageURL}"
Width="50" Height="50"/>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
FontSize="15"
FontWeight="Bold"
Text="{Binding User}"/>
<TextBlock
Grid.Row="1" TextWrapping="Wrap"
Text="{Binding Status}"/>
<DockPanel
Grid.Row="2">
<TextBlock
DockPanel.Dock="Left"
FontSize="10" TextWrapping="WrapWithOverflow"
Text="{Binding TimeAgo}" TextAlignment="Justify"/>
<TextBlock
DockPanel.Dock="Left"
FontSize="10" TextWrapping="Wrap"
Text="{Binding Source}"/>
</DockPanel>
</Grid>
</Grid>
</DataTemplate>
The problem is that it doesn't auto-size to the ListBox. The text gets clipped:
TwitBy preview
How to fix it?
Here's the listBox XAML definition:
<ListBox
x:Name="tweetsListBox"
Margin="3,0"
Grid.Row="1"
Background="{x:Null}" Grid.IsSharedSizeScope="True"
ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemTemplate="{DynamicResource Tweet}"/>
Any help would be appreciated.
Thanks
Try this:
<DataTemplate x:Key="Tweet">
<Grid Width="{Binding ElementName=tweetsListBox, Path=ActualWidth>">

Categories

Resources