Autor Beitrag
RobAll
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: So 26.05.19 23:16 
Nun versuche ich den Zugriff auf das Datagrid über eine Bindung.
Leider bleibt die Bindung zu CurrentCell und CurrentColumn leer, hat jemand eine Idee??
Im Command habe ich Focusable="False" gesetzt.
ausblenden XML-Daten
1:
2:
3:
4:
5:
6:
7:
<DataGrid 
    ...                    
    ItemsSource="{Binding StammdatenView}"  
    DataContext="{StaticResource vm}"
    CurrentCell="{Binding DataGridCurrentCell, Mode=TwoWay}"
    CurrentColumn="{Binding DataGridCurrentColumn, Mode=OneWay}"
</DataGrid>


ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
private string _CurrentColumn;
public string CurrentColumn
{
    get
    {
        MessageBox.Show (_CurrentColumn);
        return _CurrentColumn;
    }
}


Moderiert von user profile iconTh69: XML-Tags hinzugefügt
Moderiert von user profile iconTh69: C#-Tags hinzugefügt
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 27.05.19 08:36 
Da passen zum einen die Namen der Eigenschaften nicht überein (DataGridCurrentColumn <-> CurrentColumn) und dann hat deine Eigenschaft auch keinen Setter, aber du hast Mode=TwoWay angegeben.

Bei Binding-Fehlern die Warnungen im Ausgabe-Fenster vom VS beachten (evtl. den Detailgrad in den Optionen erhöhen: Vorgehensweise: Anzeigen von WPF-Ablaufverfolgungsinformationen).

Edit: Hier noch ein englischer Beitrag dazu: WPF: Debugging data bindings
RobAll Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Do 30.05.19 22:21 
ToDo
- ich möchte eine "Maus" focusierte DataGridCell über c# Code manipulieren
- XAML Focusable="False" ist im Menü Item und im Command gesetzt


ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
private DataGridCellInfo _cellInfo;
public DataGridCellInfo CellInfo
{
    get { return _cellInfo; }
    set
    {
        _cellInfo = value;
        OnPropertyChanged("CellInfo");
        MessageBox.Show(string.Format("Column: {0}",
                        _cellInfo.Column.DisplayIndex != null ? _cellInfo.Column.DisplayIndex.ToString() : "Index out of range!"));
    }
}

MVVM ... Ich versuche über das ViewModel, auf das DataGrid zuzugreifen.




Versuch:
ausblenden XML-Daten
1:
2:
3:
4:
5:
6:
7:
8:
DataContext="{StaticResource vm}"

<DataGrid AutoGenerateColumns="True"
          SelectionUnit="Cell"
          SelectionMode="Single"
          Height="250" Width="525" 
          ItemsSource="{Binding Results}"
          CurrentCell="{Binding CellInfo, Mode=OneWayToSource}"/>

Ich versuche seit Wochen vergebens auf diese Eigenschaften über get oder set zuzugreifen.

CurrentCell ist immer null!

Bitte nochmals um Hilfe

Danke vorab RobAll
RobAll Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Do 27.06.19 21:01 
Guten Abend,
leider bin ich mit meinem letzten Beitrag immer noch nicht weiter,
ist für mich als Anfänger mit WPF und MVVM nicht ganz einfach..

Hat nicht jemand eine Idee?

LG
und
Danke vorab
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Fr 28.06.19 09:08 
Funktioniert es denn mit Focusable="true"?
Wie soll denn ohne Fokus die aktuelle Zelle oder Spalte ausgewählt werden können?
RobAll Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Sa 29.06.19 12:12 
Also ich habe im DataGrid Focusable="true"
und im
ausblenden XML-Daten
1:
2:
<MenuItem Header="Bearbeiten" Background="{StaticResource MainBlue}" Margin="0,1,0,1.2" Click="MenuItem_Click_2" RenderTransformOrigin="0.5,0.504" Focusable="False" >
<MenuItem Header="{Binding Command.Text, RelativeSource={RelativeSource self}}" Command="ns:CustomCommands.NumberGenerator" Focusable="False" >

gesetzt.

CurrentCell ist null.

Moderiert von user profile iconTh69: XML-Tags hinzugefügt
Moderiert von user profile iconTh69: C#-Tags hinzugefügt
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: So 30.06.19 09:19 
Dann verstehe ich nicht, was sollen denn die MenuItems mit dem Binding (des DataGrid)zu tun haben?
RobAll Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Di 22.10.19 12:31 
Leider muss ich das Thema MVVM Binding to DataGrid CellInfo nochmal aufgreifen..
Funktioniert -> Die DataGrid ist mit Daten gefüllt, ich habe den Window Title ins VM gebunden
Der TabControl Selected Index ist ins VM gebunden

Wer hat noch eine Idee??
Ich kann den Wert CellInfo nicht abrufen, die set property wird nicht aufgerufen
Test:
ausblenden C#-Quelltext
1:
MessageBox.Show("CellInfo: " + _CellInfo.Column.Header.ToString()); -> Das Fenster wird nicht erzeugt					

->Weitere Verwendung von CellInfo = Null

XAML
ausblenden XML-Daten
1:
2:
3:
4:
<DataGrid DataContext="{StaticResource vm}" 

...
 CurrentCell="{Binding CellInfo,Mode=OneWayToSource}"     Focusable="True"


c# viewmodel vm
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
private DataGridCellInfo _CellInfo;
public DataGridCellInfo CellInfo
{
    get
    {
        return _CellInfo;
    }
    set
    {
        MessageBox.Show("CellInfo: " + _CellInfo.Column.Header.ToString());

        SetProperty(ref _CellInfo, value);                 
    }
}


Moderiert von user profile iconTh69: C#-Tags hinzugefügt
Moderiert von user profile iconTh69: XML-Tags hinzugefügt
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mi 23.10.19 11:43 
Warum verwendest du jetzt Mode=OneWayToSource anstatt, wie im ersten Beitrag, Mode=TwoWay?
RobAll Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Mi 23.10.19 13:28 
Ich benötige im VM für weitere Abfragen nur den columnheader der ausgewählten Zelle (Die Benutzteroberfläche soll nicht aktualisiert werden)
Wobei TwoWay auch nicht funktioniert.
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mi 23.10.19 14:23 
Hast du evtl. Binding-Fehler (im VS-Ausgabe-Fenster)?

Ansonsten weiß ich auch nicht weiter - dazu müßtest du dann wohl ein Testprojekt erzeugen und hier anhängen.