Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all 18858 articles
Browse latest View live

ComboBox.SelectedValue is lost when ItemsSource is updated

$
0
0

I have a ComboBox that binds SelectedValue.  The SelectedValue on the ComboBox is lost when the ItemsSource for the ComboBox is updated.  By "lost" I mean that SelectedIndex becomes -1, SelectedItem becomes null and SelectedValue becomes null. 

However, the property in the business object to which SelectedValue is bound does not change.

If I use SelectedItem instead of SelectedValue (which is not an option in my actual application) I do not see the same behavior. 

Here is some test code showing the problem.  To view the behavior:

  • Run the application
  • Select a value in the combo boxes
  • Click the "Rebuild Lists" button.

The second ComboBox will become blank.  Here is some additional interesting information:

  • If you examine the second ComboBox in Snoop the ComboBox will suddenly display the selected item correctly.
  • After the error occurs, if you get the BindingExpression for SelectedValue in the second ComboBox and call UpdateTarget() on it, the ComboBox will once again have the correct selection.

Here is the sample code:

Xaml

<Windowx:Class="WPFExperiments.ComboBoxSelectedValue"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="ComboBoxSelectedValue"SizeToContent="WidthAndHeight"x:Name="root"><Grid><Grid.RowDefinitions><RowDefinitionHeight="Auto"/><RowDefinitionHeight="Auto"/><RowDefinitionHeight="Auto"/><RowDefinitionHeight="Auto"/><RowDefinitionHeight="Auto"/></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinitionWidth="Auto"/><ColumnDefinitionWidth="Auto"/><ColumnDefinitionWidth="Auto"/></Grid.ColumnDefinitions><TextBlockGrid.Row="0"Grid.Column="0">SelectedItem:</TextBlock><TextBlockGrid.Row="1"Grid.Column="0">SelectedValue (no converter):</TextBlock><ComboBoxGrid.Row="0"Grid.Column="1"Margin="10,0,0,0"Width="100"ItemsSource="{Binding ElementName=root, Path=PrimaryColorList}"SelectedItem="{Binding ElementName=root, Path=ChildSelectedItem.FavoriteColor}"/><ComboBoxx:Name="cbNoConverter"Grid.Row="1"Grid.Column="1"Margin="10,0,0,0"Width="100"ItemsSource="{Binding ElementName=root, Path=PrimaryColorListEnumValues}"DisplayMemberPath="Display"SelectedValue="{Binding ElementName=root, Path=ChildSelectedValueNoConverter.FavoriteColor}"SelectedValuePath="Color"ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/><TextBlockGrid.Row="0"Grid.Column="2"Margin="5,0,5,0"Text="{Binding ElementName=root, Path=ChildSelectedItem.FavoriteColor, StringFormat='Favorite: {0}'}"/><TextBlockGrid.Row="1"Grid.Column="2"Margin="5,0,5,0"Text="{Binding ElementName=root, Path=ChildSelectedValueNoConverter.FavoriteColor, StringFormat='Favorite: {0}'}"/><ButtonGrid.Row="3"Grid.ColumnSpan="3"x:Name="test"Content="Rebuild Lists"Click="test_Click"/><ButtonGrid.Row="4"Grid.ColumnSpan="3"x:Name="updateBindingExpressions"Content="Update Binding Expressions"Click="updateBindingExpressions_Click"/></Grid></Window>

Code-Behind

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;namespace WPFExperiments {///<summary>/// Interaction logic for ComboBoxSelectedValue.xaml///</summary>publicpartialclass ComboBoxSelectedValue : Window {public ComboBoxSelectedValue() {
      InitializeComponent();
      BuildList(false);
      ChildSelectedItem = new ChildWithFavoriteColor();
      ChildSelectedValueNoConverter = new ChildWithFavoriteColor();
    }void BuildList(bool includePercula) {
      List<PrimaryColors> l1 = new List<PrimaryColors>();
      l1.Add(PrimaryColors.red);
      l1.Add(PrimaryColors.blue);
      l1.Add(PrimaryColors.yellow);if (includePercula) l1.Add(PrimaryColors.percula);
      PrimaryColorList = l1;

      List<PrimaryColorEnumValue> l2 = new List<PrimaryColorEnumValue>();
      l2.Add(new PrimaryColorEnumValue(PrimaryColors.red));
      l2.Add(new PrimaryColorEnumValue(PrimaryColors.blue));
      l2.Add(new PrimaryColorEnumValue(PrimaryColors.yellow));if (includePercula) l2.Add(new PrimaryColorEnumValue(PrimaryColors.percula));
      PrimaryColorListEnumValues = l2;

    }

    privatevoid test_Click(object sender, RoutedEventArgs e) {
      BuildList(true);
    }public List<PrimaryColors> PrimaryColorList {get { return (List<PrimaryColors>)GetValue(PrimaryColorListProperty); }set { SetValue(PrimaryColorListProperty, value); }
    }publicstaticreadonly DependencyProperty PrimaryColorListProperty =
      DependencyProperty.Register("PrimaryColorList", typeof(List<PrimaryColors>), typeof(ComboBoxSelectedValue),new PropertyMetadata(null));public List<PrimaryColorEnumValue> PrimaryColorListEnumValues {get { return (List<PrimaryColorEnumValue>)GetValue(PrimaryColorListEnumValuesProperty); }set { SetValue(PrimaryColorListEnumValuesProperty, value); }
    }publicstaticreadonly DependencyProperty PrimaryColorListEnumValuesProperty =
      DependencyProperty.Register("PrimaryColorListEnumValues", typeof(List<PrimaryColorEnumValue>), typeof(ComboBoxSelectedValue),new PropertyMetadata(null));public ChildWithFavoriteColor ChildSelectedItem {get { return (ChildWithFavoriteColor)GetValue(ChildSelectedItemProperty); }set { SetValue(ChildSelectedItemProperty, value); }
    }publicstaticreadonly DependencyProperty ChildSelectedItemProperty =
      DependencyProperty.Register("ChildSelectedItem", typeof(ChildWithFavoriteColor), typeof(ComboBoxSelectedValue),new PropertyMetadata(null));public ChildWithFavoriteColor ChildSelectedValueNoConverter {get { return (ChildWithFavoriteColor)GetValue(ChildSelectedValueNoConverterProperty); }set { SetValue(ChildSelectedValueNoConverterProperty, value); }
    }publicstaticreadonly DependencyProperty ChildSelectedValueNoConverterProperty =
      DependencyProperty.Register("ChildSelectedValueNoConverter", typeof(ChildWithFavoriteColor), typeof(ComboBoxSelectedValue),new PropertyMetadata(null));privatevoid updateBindingExpressions_Click(object sender, RoutedEventArgs e) {var be1 = BindingOperations.GetBindingExpression(cbNoConverter, ComboBox.SelectedValueProperty);
      be1.UpdateTarget();
    }

  }

  publicenum PrimaryColors {
    red,
    yellow,
    blue,
    percula
  }publicclass ChildWithFavoriteColor : DependencyObject {public PrimaryColors FavoriteColor {get { return (PrimaryColors)GetValue(FavoriteColorProperty); }set { SetValue(FavoriteColorProperty, value); }
    }publicstaticreadonly DependencyProperty FavoriteColorProperty =
      DependencyProperty.Register("FavoriteColor", typeof(PrimaryColors), typeof(ChildWithFavoriteColor),new PropertyMetadata(PrimaryColors.red));
  }publicclass PrimaryColorEnumValue {publicstring Display { get; set; }public PrimaryColors Color { get; set; }public PrimaryColorEnumValue(PrimaryColors color) {
      Color = color;
      Display = Color.ToString();
    }publicoverridestring ToString() {return Display;
    }
  }
}

Thanks for any help you can offer,

David Cater


Update a ListBoxItem (WPF)

$
0
0

In my WPF application I create a ListBox with this XAML code:
...
<ListBox Margin="12,46,113,12" Name="MyListBox" SelectionChanged="MyListBox_SelectionChanged"/>
...

In my C# code, I am able to retrieve the text of the currently selected item with this C# code:
...
String CurText = MyListBox.SelectedItem.ToString();
...

My problem is that I am not able to change the text of the currently selected item.  I try this, and it does not raise any errors, but it does not change the text of the selected item either:
...
MyListBox.SelectedItem = "Some New Text";
...

I just can't seem find any example code for updating the text a ListBoxItem. Please help.  I'm a good old C programmer who's new to the .Net Framework.

Thank you,
Dan

Hit Test Combobox Dropdown (From mouse location)

$
0
0

Hi

I'm having some trouble determining if the mouse has clicked within the bounds of a combobox dropdown in WPF.
I'm using a mouse Hook to determine if the mouse has been clicked outside of a certain window I'm displaying. This works fairly good.

The problem is that one of my windows has a combobox which is positioned at the bottom of the window, and the case is that if the user clicks an item from the combobox' dropdown list, the hook actually sees it as a click outside of the window's bounds (which is the case).

Now i've done some googling and found that the method I am using (VisualTreeHelper.HitTest) doesn't see the combobox' PART_Popup. Now how can I determine if the mouse's location is within the bounds of the popup of this control? 

I need a method that can work in any situation since I use it for all my dialog windows.

My other option is to make a "combobox" user control, and decide on the fly if i need to "drop down" up or down.

Any help would be greatly appreciated.

Thanks.
A.

Using trigger or behavior to change the cell's template by different conditions

$
0
0

I have  a gridview. It can be view or edited. When we view it, all the cells are readonly. When we want edit them, all cells are textbox or combobox. 

So I put the controls in the same position, switch them by the user preference. 

<GridViewColumn Header="Databases" Width="498"><GridViewColumn.CellTemplate><DataTemplate><TextBox Text="{Binding DbName}"><TextBox.Style><Style TargetType="TextBox"><Style.Triggers><DataTrigger Binding="{Binding ViewStatusVisibility" Value="Visible"><Setter Property="IsReadOnly"  Value="True" /></DataTrigger><DataTrigger Binding="{Binding ViewStatusVisibility" Value="Visible"><Setter Property="IsReadOnly"  Value="False" /></DataTrigger></Style.Triggers></Style></TextBox.Style></TextBox>                      </DataTemplate></GridViewColumn.CellTemplate></GridViewColumn>
Now my question is I want to add one more case, which is to insert new record to the grid. 
public ObservableCollection<PersonModel> GridCollection { get; set; }
public void InsertNewRow()
{
    GridCollection.Insert(0, new PersonModel());
}
In this case, I want the new row in the grid can be edited and the other existing rows are read only. The template I provided is not working for this case because it impacts all rows rather than the specific row. In other words, by that template, all the rows are read only or all can be edited. I am thinking should I use behavior or other skills to solve it? 

Thanks for code help.

I am using C# WPF about notification

$
0
0

if you see picture How can I do smiller notificatıon menu  please help me  I don't know it please help me

wpf project with C++/CLI dll System.IO.FileNotFoundException

$
0
0

I create 32bit wpf application with C++/CLI. It runs without problem on my notebook with Windows 7 64b HomeEdition, secondary Windows 7 32b notebook, Windows 10 64b notebook, Windows 8 32b PC. But under Windows 10 64b it stop worked. It throw this:

System.IO.FileNotFoundException: Could not load file or assembly "wrapper.dll" (which is my dll) or one of its dependencies. The specified module could not be found.

Here is full text:

But strange is, my program worked on that system (Windows 10 64b), but today it is not working even older versions of my programs. I have no clue what happens.

What I tried is make for all references inside my wpf project set Copy Local = True. It add lot of dlls inside my release folder, but it doesn't help.

Btw. paths in text I post above, are from my development notebook, but program which throw this error was run under windows 10 64b. 

Get file download paths from WPF WebBrowser

$
0
0

Is there a way to get the file path of a downloaded file when using the WebBrowser control? I've seen that for WinForms you can subclass the WebBrowser and hook in your own IDownloadManager but I can't find a way to do that for WPF's WebBrowser.

At the moment I am trying to figure out whether a navigated URL is for a file in the Navigating event but there are many edge cases where this could fail. Also, it's a bit of an overkill since I just want to know the path that the user saved the file to.

loop for each line in richTextBox in WPF

$
0
0

I am new to wpf, I need to read line by line from richTextBox, I used this down code in winforms but in wpf there is no  "richTextBox1.Lines". how to do it?

 for (int i = 0; i <= richTextBox1.Lines.Length - 1; i++)
 {
  ....
 }


Dynamic Combo Box parameters resetting

$
0
0

I've created a report control that takes a set of parameters bound to an underlying object and generates the controls using a data template selector.

<local:ReportControlGrid.Row="1"Grid.ColumnSpan="2"><local:ReportControl.Parameters><local:ReportParameterLabel="Combo Box"ItemsSource="{Binding ItemsSource}"Value="{Binding [value]}"/><local:ReportParameterLabel="Text"Value="{Binding [text]}"/></local:ReportControl.Parameters></local:ReportControl>

The problem I have is when I used this with multiple reports selected from a dropdown list, switching between reports resets the combobox values, but not any of the other values.

A copy of a Toy application that shows the problem I'm having can be found on github here where I have a tab control with two tabs and on the first tab there is a dropdown list that shows 2 reports.

Returning to first report with combo box value has disappeared.

Initial entry of toy reproduction

Entering value for the second report

The TestViewModel class sets up the reports, and the MainWindow sets up the main UI for displaying the reports. To simulate the fact that in the production app the reports can come from multiple locations and so have their own view attached for distinct parameter configuration, the Report Class has a ReportView object that declares the parameters as above. Finally, the ReportControl and ReportParameter reproduces the Main report control and parameters that are added. I've only implemented a basic freeflow text and combobox list as the parameters to prove that it's a problem with the combobox bindings. The template selector and data type enum can also be found in ReportParameter.cs.

Would anyone have any ideas why the comboboxes are resetting, but they don't reset if the report is configured in the xaml without the additional abstraction of using a content control? Ideas on how to fix this would also be useful.



Accessing Controls from Duplicated Tabs

$
0
0

Hello,

I'm developing an application with WPF that requires the use of dynamic tabs. A TabItem is created for each item in a list and duplicated from a hidden "tabToDuplicate" and added to TabControl:

<TabItem Header=" " Name="tabToDuplicate" Visibility="Hidden"><Grid Background="#FFE5E5E5"><DataGrid Name="BookData" Margin="10,10,409,25" RenderTransformOrigin="-0.63,0.07" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"></DataGrid> <Button Content="Button" HorizontalAlignment="Left" Margin="304,59,0,0" VerticalAlignment="Top" Width="80" Height="23"/></Grid></TabItem>
private void Window_Initialized(object sender, EventArgs e)
{
           foreach (string i in TabList)
                TabControl.Items.Insert(TabControl.Items.Count-1, NewTabItem(i));
}
private TabItem NewTabItem(string Name)
{
            TabItem NewTab = CloneObject(tabToDuplicate);
            NewTab.Name = "tab" + Name;
            NewTab.Header = Name;
            NewTab.Visibility = Visibility.Visible;
            return NewTab;
}

The TabItem is successfully added and duplicated correctly. I'm not sure how to access child controls created within the new duplicated TabItem to get/set properties etc. Please can I have some advice.

Thank you.

C# WPF LiveChart Update data series in dynamicly created charts

$
0
0

Can anyone give advice on how to update all dynamicly created charts(10-12 charts) with dynamicly created series(3-5 series per chart) code below on how charts and series are created: Page part where all charts and pages are assembled:

    public ChartPage()
    {
        InitializeComponent();
        for(int i = 0; i < ChartConnector.FoundMainData; i++)
        {
            GroupedCharts SC = new GroupedCharts();
            foreach (string SGDO in ChartConnector.MainDataTable[i].SecondLevelData.Keys)
            {


                SingleChartObject SingleChart = new SingleChartObject ();

                for (int z = 0; z < ChartConnector.MainDataTable[i].SecondLevelData[SGDO].FoundThirdLevelData; z++)
                {
                    SingleChart.AddNewLineToChart(ChartConnector.MainDataTable[i].SecondLevelData[SGDO].ThirdLevelData[z].ThirdLevelDataName, Convert.ToDouble(ChartConnector.MainDataTable[i].SecondLevelData[SGDO].ThirdLevelData[z].ThirdLevelDataValue));
                }
                SC.AddChartToGroup(SingleChart);
            }
            ChartList.Children.Add(SC);
        }
    }

ChartList in ChartPage xaml

<StackPanel x:Name="ChartList"></StackPanel>

GroupedCharts are UserControl which stores charts from second level data GroupedCharts AddChartToGroup function below:

public void AddChartToGroup(SensorChart ChartBlock)
    {
         ChartGroup.Children.Add(ChartBlock);
    }

Chartgroup in xaml code below:

<WrapPanel Orientation="Horizontal" x:Name="ChartGroup"></WrapPanel>


public void AddNewLineToChart(string Name, double Value)
    {
        ChartValues<LiveCharts.Defaults.ObservableValue> observableValues = new ChartValues<LiveCharts.Defaults.ObservableValue>
        {
            new LiveCharts.Defaults.ObservableValue(Value)
        };
        LiveCharts.Wpf.LineSeries FreshLines = new LineSeries
        {
            Values = observableValues,
            Title = Name

        };
        ChartBlock.Series.Add(FreshLines);
    }

Chart it self in SingleChartObject:

<lvc:CartesianChart x:Name="ChartBlock" Height="125" Width="300" Pan="None" ><lvc:CartesianChart.DataTooltip><lvc:DefaultTooltip SelectionMode="SharedYInSeries" /></lvc:CartesianChart.DataTooltip></lvc:CartesianChart>

Now main question how to update all charts at a same time, I have no idea on how to do such massive update. Thanks for help.

help with learning WPF (question)

$
0
0

Hello 

I know little about WPF and mostly I learned from searching on google for my needs. I know C++ and start learning C# (know basics) for using WPF. Questions are

1. can I skip learning C# and dive in to WPF study? I want stay with C++ programing but use WPF as GUI. I am asking because WPF looks big. Lot of possibilities in programing but in designing UI too. Someone can do one thing in lot of different ways, from XAML only to code behind only.

2. is Microsoft documentation good to learn WPF? Or it is better look for elsewhere? Maybe both, Microsoft and outside tutorials?

Datagrid Selected Cells Row Index and Column Index into list.

$
0
0

Datagrid Selected Cells Row Index and Column Index into list. Using Attached Property. Huge Performance Issue.

 public class RowNumberDp
    {
        public static DependencyProperty DisplayRowNumberProperty =
            DependencyProperty.RegisterAttached("DisplayRowNumber",
                typeof(bool),
                typeof(RowNumberDp),
                new FrameworkPropertyMetadata(false, OnDisplayRowNumberChanged));

        public static bool GetDisplayRowNumber(DependencyObject target)
        {
            return (bool) target.GetValue(DisplayRowNumberProperty);
        }

        public static void SetDisplayRowNumber(DependencyObject target, bool value)
        {
            target.SetValue(DisplayRowNumberProperty, value);
        }

        private static void OnDisplayRowNumberChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            if (!(target is DataGrid dataGrid)) return;       
            dataGrid.SelectedCellsChanged += Selectedcells;
        }

        private static void Selectedcells(object sender, SelectedCellsChangedEventArgs e)
        {
        
            if (!(sender is DataGrid datagrid)) return;           
            foreach (DataGridCellInfo obj in datagrid.SelectedCells)
            {
	    var rowIndex = datagrid.Items.IndexOf(obj.Item)
              var ColumnName = obj.Column.SortMemberPath;
            }           
               
        }      
        
    }


Problem Statement : Row Index is

causing huge performance Issue ...If I comment rowIndex  everything works Super Fast..

I need rowindex for SelectedCells.

I tried Different approach as well.

 1. 

     private static List<Tuple<int, int>> GetRowAndColumnIndicesFromGivenCell(DataGrid dataGrid, DataGridCell cell)
        {
            List<Tuple<int, int>> cellList = null;

            var columnIndex = cell.Column.DisplayIndex;
            var parent = VisualTreeHelper.GetParent(cell);
            while (parent != null && parent.GetType() != typeof(DataGridRow))
            {
                parent = VisualTreeHelper.GetParent(parent);
            }

            if (parent is DataGridRow)
            {
                var dataGridRow = parent as DataGridRow;
                var item = dataGridRow.Item;
                if (item != null)
                {
                    var rowIndex = dataGrid.Items.IndexOf(item);
                    if (rowIndex != -1)
                    {
                        cellList = new List<Tuple<int, int>>()
                        {
                            new Tuple<int, int>(rowIndex, columnIndex)
                        };
                    }
                }
            }

            return cellList;
        }

from above code...Only Visible Datagrid Rows will come....But Scrolling does not happen,

Example If i select 1 to 1000 Only 986 to 1000 Numbers will Show. 



MVVM - Collections of VMs

$
0
0

I have a rather typical scenario, i.e. a model A that has a collection of models B. I also have a VM A and VM B for the two models. The question is, how do I expose the collections of VM Bs in VM A. I did a lot of googling and the best post I found was this: https://stackoverflow.com/questions/15830008/mvvm-and-collections-of-vms That looks pretty interesting but how do you actually use this, in particular the IViewModelProvider that needs to be passed to the constructor.

I am also interested in any other suggestions how to implement this.

 

How to get MouseOver from a ListBoxItem in .NET 3.5 WPF MVVM?

$
0
0

My client has a WPF application that must be able to run on .NET 3.5. This application has a ListBox whose DataSource is bound to an ObservableList in a ViewModel. Each ListBoxItem in the ListBox, of course, is bound to a member in the ObservableList, an LbiModel. The goal is to set a bool property in the LbiModel when the cursor is over the associated ListBoxItem. I've spent a lot of time trying to figure out how to solve the solution but haven't come up with anything acceptable. Likewise, I've Googled existing solutions but no luck. Suggestions?


Richard Lewis Haggard


get all selected items from wpf checkbox list give me error

$
0
0

I have listbox with checked box as following, & it binding its data from sql server database,
, I want to get selected items value When I run this but I got this error
 
Unable to cast object of type 'System.Data.DataRowView' to type 'System.Windows.Controls.CheckBox'.

<Window.Resources><DataTemplate x:Key="NameColumnTemplate"><CheckBox Height="20"  FontFamily="Arial" FontSize="14"  Content="{Binding Path=PermissionDescription}" 
                      Tag="{Binding PermissionID}" HorizontalAlignment="Stretch" VerticalAlignment="Center"
                      /></DataTemplate></Window.Resources><Grid><ListBox HorizontalAlignment="Stretch" Margin="12,12,136,21" Name="lstEmployees" 
                          VerticalAlignment="Stretch" ItemsSource="{Binding Tables[0]}"  
                          ItemTemplate="{StaticResource NameColumnTemplate}" 
                          ScrollViewer.VerticalScrollBarVisibility="Auto" removed="{x:Null}" 
                         BorderBrush="#FFAD7F30"  
                 SelectionChanged="lst_SelectionChanged" CheckBox.Click="lst_SelectionChanged"/><Button Content="listbox" Height="23" HorizontalAlignment="Left" Margin="214,207,0,0" Name="btnShowSelectedItems" 
                VerticalAlignment="Top" Width="75" Click="btnShowSelectedItems_Click" /></Grid>

public Window2()
        {
            InitializeComponent();
            // bind data 
            lstEmployees.DataContext = SelJobsCat();
        }
 
 private void btnShowSelectedItems_Click(object sender, RoutedEventArgs e)
        {
            foreach (CheckBox item in lstEmployees.Items)
            {
                if (item.IsChecked == true)
                {
                    System.Windows.MessageBox.Show((item.Content + " is checked."));
                }
            }
        }
        private void lst_SelectionChanged(object sender, RoutedEventArgs e)
        {
            if (e.OriginalSource is CheckBox)
            {
                lstEmployees.SelectedItem = e.OriginalSource;
            }
            if (lstEmployees.SelectedItem == null) return;
            Console.WriteLine(lstEmployees.SelectedIndex);
            Console.WriteLine(((CheckBox)lstEmployees.SelectedItem).IsChecked);
        }
where is my error please, Thanks

Performance Issue with Row Number but Column Number Working Super Fast.

$
0
0

Performance Issue with Row Number but Column Number Working Super Fast.

       foreach (DataGridCellInfo obj in datagrid.SelectedCells)
            {
               var selectedcells = new SelectedCellsModel
                {
                RowNumber = datagrid.Items.IndexOf(obj.Item),
                ColumnName = obj.Column.SortMemberPath
                };

                updateVm.Collection.SelectedCells.Add(selectedcells);
            }

Reflection not working to get run time Property Values in DataGridCellInfo

$
0
0

Reflection not working to get run time Property Values in DataGridCellInfo.

Wpf - Datagrid - SelectedCellsChanged - Changed Event

 private void Dgv_OnSelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            var pp = e.AddedCells[0];
            PropertyInfo rowDataItemProperty = pp.GetType().GetProperty("ItemInfo", BindingFlags.Instance | BindingFlags.NonPublic);
        }
<DataGrid Name="dgv" RowHeaderWidth="50" SelectedCellsChanged="Dgv_OnSelectedCellsChanged"  SelectionUnit="CellOrRowHeader"  AutoGenerateColumns="False" ItemsSource="{Binding ViewModelCollection}" IsSynchronizedWithCurrentItem="True" CanUserAddRows="False" MinColumnWidth="80" ColumnWidth="80" CanUserResizeRows="False" CanUserResizeColumns="False" Margin="0,55,-0.287,0.168"><DataGrid.Columns><DataGridTextColumn Header="Dosage" Binding="{Binding Path=Dosage}" /><DataGridTextColumn Header="Drug" Binding="{Binding Path=Drug}" /><DataGridTextColumn Header="Patient" Binding="{Binding Path=Patient}"/><DataGridTextColumn Header="Date" Binding="{Binding Path=Date}"/></DataGrid.Columns></DataGrid>


My Requirement is Simple.

I Just Need the Index, But after getting into ItemInfo Property I dont see Index.....

pp.ItemInfo	Index: 2  Item: {WpfApp22.Model}	System.Windows.Controls.ItemsControl.ItemInfo

At runtime index changes.....

I need Just Index Number .

wpfgfx_v0400.dll issue in wpf application

$
0
0

Hi Team,

      We are getting following exception in our WPF <g class="gr_ gr_33 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="33" id="33">application</g>. Please provide the reason or solution for the below errors. 

                wpfgfx_v0400.dll!CPtrArrayBase::GetCount(void)            Unknown

               wpfgfx_v0400.dll!CPtrMultisetBase::Remove(unsigned int)        Unknown

               wpfgfx_v0400.dll!CMilSlaveResource::UnRegisterNotifierInternal(class CMilSlaveResource *)    Unknown

               wpfgfx_v0400.dll!CMilSlaveRenderData::DestroyRenderData(void)         Unknown

               wpfgfx_v0400.dll!CMilSlaveRenderData::~CMilSlaveRenderData(void)  Unknown

               wpfgfx_v0400.dll!CMilSlaveRenderData::`vector deleting destructor'(unsigned int)         Unknown

               wpfgfx_v0400.dll!CMILCOMBase::InternalRelease(void)               Unknown

               wpfgfx_v0400.dll!CBaseWGXBitmap::Release(void)        Unknown

               wpfgfx_v0400.dll!CMilSlaveHandleTable::DeleteHandle(unsigned int)    Unknown

               wpfgfx_v0400.dll!CComposition::ReleaseResource(class CMilSlaveHandleTable *,unsigned int,class CMilSlaveResource *,bool)          Unknown

               wpfgfx_v0400.dll!CComposition::Channel_DeleteResource(class CMilServerChannel *,class CMilSlaveHandleTable *,struct MILCMD_CHANNEL_DELETERESOURCE const *) Unknown

               wpfgfx_v0400.dll!CComposition::ProcessCommandBatch(class CMilCommandBatch *)  Unknown

               wpfgfx_v0400.dll!CComposition::ProcessPartitionCommand(class CMilCommandBatch *,bool)  Unknown

               wpfgfx_v0400.dll!CCrossThreadComposition::ProcessBatches(bool)       Unknown

               wpfgfx_v0400.dll!CCrossThreadComposition::OnBeginComposition(void)            Unknown

               wpfgfx_v0400.dll!CComposition::ProcessComposition(bool *)   Unknown

               wpfgfx_v0400.dll!CComposition::Compose(bool *)         Unknown

>             wpfgfx_v0400.dll!CPartitionThread::RenderPartition(class Partition *)    Unknown

               wpfgfx_v0400.dll!CPartitionThread::Run(void)   Unknown

               wpfgfx_v0400.dll!CPartitionThread::ThreadMain(void *)              Unknown

               kernel32.dll!@BaseThreadInitThunk@12‑()         Unknown

               ntdll.dll!___RtlUserThreadStart@8‑()     Unknown

               ntdll.dll!__RtlUserThreadStart@8‑()       Unknown

              


TextBox character/letter spacing?

$
0
0

Back in WPF 3.5-4.0, I remember not being able to change the letter spacing for TextBox (and other Text elements) (not stretch nor scale, but spacing).

Is this achievable now with WPF (2018)?

For Labels/TextBlocks, I was able to use an ItemsControl. But not for TextBox.

If not, is there a page where I can request/vote for this (like Connect)?

And how can I workaround this in the meantime?

Thanks

mc

(2008) Increase the Character spacing in a textblock

(2010) Character spacing in a label


Viewing all 18858 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>