Hi,
I have two columns in my XamDataGrid. In on of the columns, I want to fix maxheight, and width to be Auto (which means it should adjust with column resize, have text wrap depending upon available width and also have vertical scroll bar to appear as auto. Width and height are set but wrapping doesn't work and scrolling also doesn't appear.
This is how I am trying to achieve this.
f.DataType = typeof(string); f.Settings.EditorType = typeof(XamTextEditor); f.Settings.EditorStyle = new Style(typeof(XamTextEditor)); f.Settings.EditorStyle.Setters.Add(new Setter(XamTextEditor.TextWrappingProperty, TextWrapping.Wrap)); f.Settings.EditorStyle.Setters.Add(new Setter(XamTextEditor.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Auto));
Thanks,
Imad.
Hello Imad,
Thank you for the provided feedback. Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Hi Krasimir,
I tried that solution, but for some reason not working for me. I don't know if there is anyother field that is preventing scrollbar to appear.
Here is my code with bold section where I want Scroll bar to appear. I hope you can figure out the problem.
Watiing for your response.
e.FieldLayout.Settings.AutoArrangeCells = AutoArrangeCells.LeftToRight; e.FieldLayout.Settings.DataRecordSizingMode = DataRecordSizingMode.SizedToContentAndIndividuallySizable; e.FieldLayout.DataPresenter.FieldSettings.AutoSizeOptions = FieldAutoSizeOptions.All; e.FieldLayout.DataPresenter.FieldSettings.AutoSizeScope = FieldAutoSizeScope.AllRecords; e.FieldLayout.DataPresenter.FieldLayoutSettings.AutoFitMode = AutoFitMode.ExtendLastField; e.FieldLayout.FieldSettings.AllowRecordFiltering = false; //Disable Filtering in Activity List Type objectType; //Double width = ActivityViewDg.ActualWidth; foreach (Field f in e.FieldLayout.Fields) { if (f.DataType == typeof(MyData)) { f.Visibility = Visibility.Collapsed; continue; } f.Settings.AllowEdit = false; f.Settings.LabelTextAlignment = TextAlignment.Left; objectType = f.DataType; f.DataType = typeof(string); f.Width = FieldLength.Auto; f.Settings.LabelTextWrapping = TextWrapping.Wrap; f.Settings.LabelClickAction = LabelClickAction.SortByOneFieldOnly; // update header style to include automation id Style style = new Style(typeof(LabelPresenter), Infragistics.Windows.Themes.DataPresenterGeneric.LabelPresenter); Setter setter = new Setter(); setter.Property = System.Windows.Automation.AutomationProperties.AutomationIdProperty; setter.Value = f.Name; style.Setters.Add(setter); f.Settings.LabelPresenterStyle = style; if (f.Name == "FirstField") { f.Label = ManagedResources.FindResourceString("FirstFieldKey"); f.DataType = typeof(string); f.Settings.EditorType = typeof(XamDateTimeEditor); f.Settings.EditorStyle = new Style(typeof(XamDateTimeEditor)); f.Settings.EditorStyle.Setters.Add(new Setter(XamDateTimeEditor.FormatProperty, "G")); var fsD = new FieldSortDescription { IsGroupBy = false, Field = f, FieldName = f.Name, Direction = ListSortDirection.Ascending }; e.FieldLayout.SortedFields.Add(fsD); } else { if (f.Name == "SecondField") { f.Label = ManagedResources.FindResourceString("SecondFieldKey"); f.DataType = typeof(string); f.Settings.EditorType = typeof(XamTextEditor); f.Settings.EditorStyle = new Style(typeof(XamTextEditor)); f.Settings.EditorStyle.Setters.Add(new Setter(XamTextEditor.WidthProperty, double.NaN)); f.Settings.EditorStyle.Setters.Add(new Setter(XamTextEditor.HeightProperty, (double)50)); //f.Settings.EditorStyle.Setters.Add(new Setter(XamTextEditor.MaxHeightProperty, (double)150)); f.Settings.EditorStyle.Setters.Add(new Setter(XamTextEditor.TextWrappingProperty, TextWrapping.Wrap)); f.Settings.EditorStyle.Setters.Add(new Setter(XamTextEditor.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Visible)); } } if (objectType == typeof(DateTime)) { f.Visibility = Visibility.Visible; f.Converter = _dataTranslator; f.ConverterParameter = f.Name; } }
And this is the Xaml part:
<igDP:XamDataGrid Grid.Row="1" x:Name="MyGrid" AutoFit="True" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" GroupByAreaLocation="None" BorderBrush="Black" BorderThickness="1"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AddNewRecordLocation="OnBottomFixed" AllowAddNew="False" AllowDelete="False" AutoGenerateFields="True" FilterUIType="LabelIcons"/> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings AllowRecordFiltering="True" CellClickAction="SelectCell" AllowGroupBy="False"/> </igDP:XamDataGrid.FieldSettings> </igDP:XamDataGrid>
I got back to fix this problem but came to know that scroll bar only appears if AllowEdit is true, otherwise scroll bar doesn't appear.
I my case I have to have AllowEdit= false, how can I still make scroll bar to appear?
imad.
Anyone please?
I am posting this solution for anyone out there trying to solve similar problem. I changed the style and added SimpleTextBlock in ScrollViewer. Once you set MaxHeight and VerticalScrollbarVisibility to Auto, scrollbar will appear in non-edit mode as well. Here is my solution:
<!-- _________________________ TextEditor __________________________________________ --> <Style x:Key="XamTextEditorExStyle" TargetType="{x:Type igEditors:XamTextEditor}"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" /> <Setter Property="BorderBrush" Value="{DynamicResource {x:Static igEditors:EditorsBrushKeys.EditorsNormalBorderFillKey}}" /> <Setter Property="BorderThickness" Value="1" /> <Setter Property="Padding" Value="2,2,2,2" /> <!-- MD 4/26/11 - TFS73532 - This causes major slowdowns and doesn't provide much value so use a hard coded value instead. --> <!--<Setter Property="Margin" Value="{DynamicResource {x:Static igEditors:EditorsBrushKeys.TextEditorMarginKey}}" />--> <Setter Property="Margin" Value="1" /> <Setter Property="SnapsToDevicePixels" Value="True"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igEditors:XamTextEditor}"> <Border x:Name="MainBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" > <!-- SSP 10/3/07 BR25672 Took the following code out of Border element above since the TextBlock below is already setting that value. We don't want to substract the padding twice. Margin="{TemplateBinding Padding}"--> <!-- MD 8/12/10 - TFS26592 - Use the SimpleTextBlock instead --> <!--<TextBlock x:Name="TextBlock"-->
<!--scroll viewer to enable scrolling in non Edit mode --> <ScrollViewer HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}" VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}"> <igWindows:SimpleTextBlock x:Name="TextBlock" Margin="{TemplateBinding Padding}" Text="{TemplateBinding DisplayText}" TextWrapping="{TemplateBinding TextWrapping}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" TextAlignment="{TemplateBinding TextAlignmentResolved}" /> </ScrollViewer> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEmbedded" Value="False"> <Setter TargetName="MainBorder" Property="CornerRadius" Value="1" /> <!-- MD 10/27/10 - TFS38066 - We shouldn't optimize the width measurements when this is a standalone editor --> <Setter Property="igWindows:SimpleTextBlock.OptimizeWidthMeasurement" Value="False" /> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="EditTemplate"> <Setter.Value> <ControlTemplate TargetType="{x:Type igEditors:XamTextEditor}"> <Border x:Name="MainBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" > <!-- SSP 10/3/07 BR25672 Took the Margin="{TemplateBinding Padding}" code out of Border element above and instead added Padding="{TemplateBinding Padding}" to the TextBox below. Padding should not be outside the border and the background. It should be inside the border and around the editor's contents.--> <!-- AS 2/3/09 TFS13387 Added template binding to the SpellCheck properties --> <!-- JJD 11/29/10 - TFS58984 - Added AcceptsReturn and AcceptsTab properties --> <!-- SSP 6/24/11 TFS57835 Added InputMethod.PreferredImeState template binding. --> <TextBox Name="PART_FocusSite" Padding="{TemplateBinding Padding}" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="{TemplateBinding AcceptsReturn}" AcceptsTab="{TemplateBinding AcceptsTab}" TextWrapping="{TemplateBinding TextWrapping}" HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}" VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" TextAlignment="{TemplateBinding TextAlignmentResolved}" IsReadOnly="{TemplateBinding ReadOnly}" MaxLength="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ValueConstraint.MaxLength, Mode=OneWay}" Background="Transparent" BorderBrush="Transparent" BorderThickness="0,0,0,0" Foreground="{TemplateBinding Foreground}" ContextMenu="{TemplateBinding ContextMenu}" SpellCheck.IsEnabled="{TemplateBinding SpellCheck.IsEnabled}" SpellCheck.SpellingReform="{TemplateBinding SpellCheck.SpellingReform}" InputMethod.PreferredImeState="{TemplateBinding InputMethod.PreferredImeState}" /> </Border> <!-- SSP 6/6/07 BR23366 Added trigger that sets IsTabStop to False based on IsInEditMode setting. We need this in order to make the Tab and Shift+Tab navigation work properly. Apparently presense of nested textbox causes Shift+Tab to misbehave and cause the framwork to give focus to the parent ContentPresenter if the editor is inside a HeaderedContentControl. This is similar to what inbox ComboBox does. --> <ControlTemplate.Triggers> <Trigger Property="IsInEditMode" Value="True"> <Setter Property="IsTabStop" Value="False" /> <Setter Property="Padding" Value="0,2,2,2"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsEmbedded" Value="True"> <Setter Property="BorderThickness" Value="0"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsEmbedded" Value="True"/> <Condition Property="IsInEditMode" Value="True"/> </MultiTrigger.Conditions> <Setter Property="BorderThickness" Value="0"/> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsEmbedded" Value="True"/> <Condition Property="IsInEditMode" Value="False"/> </MultiTrigger.Conditions> <Setter Property="Background" Value="{x:Null}"/> <Setter Property="BorderBrush" Value="{x:Null}"/> <Setter Property="Padding" Value="2,2,2,2"/> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsEmbedded" Value="False"/> <Condition Property="IsInEditMode" Value="True"/> </MultiTrigger.Conditions> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/> </MultiTrigger> <!-- SSP 1/8/08 BR29482 - Added setter for setting Foreground. We were already setting the Background explicitly above. If we don't do this then the Foreground will be inherited but not the background. This causes a problem when the editor is inside an item of a ListBox and the item is selected. The item's back color turns blue and fore color turns white. However the editor inherits only the fore color and causes the contents to turn white, essentially disappear since the background is explicitly set to white above. Also TextBox explicitly sets both the Background and Foreground. --> <!--<Trigger Property="IsEmbedded" Value="False"> <Setter Property="Foreground" Value="#000000" /> </Trigger>--> <Trigger Property="IsEnabled" Value="False"> <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.InactiveBorderBrushKey}}"/> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" /> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" /> </Trigger> </Style.Triggers> </Style>