Hello Community,
i have a problem with one part of my current project.
I have post it in this category because i Think it´s no problem from the WPF-Side...I have to be a problem with my C#-Code...But I didn´t know where is it...
I have to control a Datagrid from another class
For better overview I have eliminated some of my code, but this is not important for the problem.
Here is my current Code from the Usercontrol. Here is my Datagrid inside:
- <UserControl x:Class="Lagerverwaltung_V3_0_Ribbon.MainFrame.TabItemArticle"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:local="clr-namespace:Lagerverwaltung_V3_0_Ribbon.MainFrame"
- xmlns:control = "clr-namespace:Lagerverwaltung_V3_0_Ribbon.Article">
- <StackPanel>
- <Button Height="20" Content="Test" Click="Button_Click"/>
- <DataGrid x:Name="dgArticle" AutoGenerateColumns="False" HeadersVisibility="None" IsReadOnly="True">
- <DataGrid.Columns>
- <DataGridTemplateColumn Width="*">
- <DataGridTemplateColumn.CellTemplate>
- <DataTemplate>
-
- <Label Name="ArticleID" Grid.Column="1" Content="{Binding ArticleID}" Margin="10,0,10,0" VerticalAlignment="Center"/>
- </DataTemplate>
- </DataGridTemplateColumn.CellTemplate>
- </DataGridTemplateColumn>
- </DataGrid.Columns>
- </DataGrid>
- </StackPanel>
- </UserControl>
and the C# Code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- 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.Navigation;
- using System.Windows.Shapes;
-
- namespace Lagerverwaltung_V3_0_Ribbon.MainFrame
- {
- public partial class TabItemArticle : UserControl
- {
- public TabItemArticle()
- {
- InitializeComponent();
- }
-
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- var data = new Test
- {
- ArticleID = "#00010000",
- };
-
-
- dgArticle.Items.Add(data);
- }
- public class Test
- {
- public string ArticleID { get; set; }
- }
- }
- }
And this is the Form where i want to Control it (my Main Window):
- <Window x:Class="Lagerverwaltung_V3_0_Ribbon.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic"
- xmlns:TabItemGrid="clr-namespace:Lagerverwaltung_V3_0_Ribbon.MainFrame"
- xmlns:local="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
- xmlns:system="clr-namespace:System;assembly=mscorlib"
- Title="Employee Info" Width="1400" Height="768">
- <TabControl TabStripPlacement="Left" VerticalAlignment="Stretch" BorderBrush="#FF6593CF" BorderThickness="1,1,1,0" Style="{DynamicResource OutlookTabControlStyle}" SelectionChanged="TabControl_SelectionChanged">
- <TabItem x:Name="MainWindow_SideControl_TabItem_Article" Header="Article">
-
- <ScrollViewer VerticalScrollBarVisibility="Auto">
- <!-- Here the user control is imported -->
- <TabItemGrid:TabItemArticle x:Name="tabItem_Article"/>
- </ScrollViewer>
-
- </TabItem>
- </TabControl>
- <Button Height="20" Label="TestButton" Click="RibbonButton_Click" />
- </Window>
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- 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.Navigation;
- using System.Windows.Shapes;
- using System.Windows.Controls.Ribbon;
- using System.Threading;
-
- namespace Lagerverwaltung_V3_0_Ribbon
- {
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
-
- }
-
- public class Test
- {
- public string ArticleID { get; set; }
- }
-
-
- private void RibbonButton_Click(object sender, RoutedEventArgs e)
- {
- MainFrame.TabItemArticle TabArticle = new MainFrame.TabItemArticle();
- var data = new Test
- {
- ArticleID = "#00010000",
- };
-
- TabArticle.dgArticle.Items.Add(data);
- }
- }
- }
My Problem is, that i can´t add a row to the datagrid with the button from the MainWindow.
Add a Row from the 'MainFrame.TabItemArticle' Control is no problem.
I hope you can understand my problem despite my bad english ...
Thank you for tips or other...
Greetings from Germany
Kai Listner