Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf Devexpress:如何在datatemplate中访问控制_Wpf_Vb.net_Devexpress_Datatemplate_Devexpress Gridcontrol - Fatal编程技术网

Wpf Devexpress:如何在datatemplate中访问控制

Wpf Devexpress:如何在datatemplate中访问控制,wpf,vb.net,devexpress,datatemplate,devexpress-gridcontrol,Wpf,Vb.net,Devexpress,Datatemplate,Devexpress Gridcontrol,我在主网格中有一个细节网格。但是,内部网格被放入datatemplate中,因此我无法在代码隐藏中访问它。我想在代码中设置Innergrid列宽,并隐藏Innergrid的第一列。稍后,我将从三个gridcontrol(TopModelDatagrid、OptionDatagrid、InnerGridcontrol)向新的gridcontrol添加拖放功能。因此,我需要从代码访问它。有人能建议我如何用代码访问它吗 MainWindow.xaml <dx:ThemedWindow

我在主网格中有一个细节网格。但是,内部网格被放入datatemplate中,因此我无法在代码隐藏中访问它。我想在代码中设置Innergrid列宽,并隐藏Innergrid的第一列。稍后,我将从三个gridcontrol(TopModelDatagrid、OptionDatagrid、InnerGridcontrol)向新的gridcontrol添加拖放功能。因此,我需要从代码访问它。有人能建议我如何用代码访问它吗

MainWindow.xaml

<dx:ThemedWindow 
    x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
    xmlns:local="clr-namespace:Master_Detail"
    Title="MainWindow" Height="800" Width="1000">
    <Grid>
        <Grid Margin="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="27*"/>
                <RowDefinition Height="347*"/>
                <RowDefinition Height="22*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>

            <Grid Margin="0,0,0,0" Grid.RowSpan="2">
                <Grid.RowDefinitions>
                    <RowDefinition Height="43*"/>
                    <RowDefinition Height="54*"/>
                </Grid.RowDefinitions>
                <dxg:GridControl x:Name="TopModelDatagrid" SelectionMode="Row" AutoGenerateColumns="AddNew" EnableSmartColumnsGeneration="True"  Margin="0,0,0,0" >
                    <dxg:GridControl.View>
                        <dxg:TableView x:Name="TopModelTableView" AutoWidth="True"/>
                    </dxg:GridControl.View>
                </dxg:GridControl>

                <dxg:GridControl  x:Name="OptionDatagrid"  SelectionMode="Row" AutoGenerateColumns="AddNew" EnableSmartColumnsGeneration="True" Margin="0,0,0,0" Grid.Row="1">
                    <dxg:GridControl.View>
                        <dxg:TableView
                            x:Name="OptionTableView"
                            AllowMasterDetail="True"
                            AutoWidth="True"
                            IsDetailButtonVisibleBinding="{Binding Row.Opt, Converter={local:IsTopModelConverter}}"/>
                    </dxg:GridControl.View>
                    <dxg:GridControl.DetailDescriptor>
                        <dxg:ContentDetailDescriptor>
                            <dxg:ContentDetailDescriptor.ContentTemplate>
                                <DataTemplate>
                                    <dxg:GridControl AutoGenerateColumns="AddNew" x:Name="InnerGrid" MaxHeight="1000"
                                                     ItemsSource="{Binding MasterRowData.View.Grid.ItemsSource, RelativeSource={RelativeSource TemplatedParent}}"
                                                     FixedFilter="{Binding Opt, Converter={local:FilterConverter}}">
                                        <dxg:GridControl.View>
                                            <dxg:TableView x:Name="InnerGridTableView" ShowGroupPanel="False" AutoWidth="True"/>
                                        </dxg:GridControl.View>
                                    </dxg:GridControl>
                                </DataTemplate>
                            </dxg:ContentDetailDescriptor.ContentTemplate>
                        </dxg:ContentDetailDescriptor>
                    </dxg:GridControl.DetailDescriptor>
                </dxg:GridControl>
            </Grid>
        </Grid>
    </Grid>
</dx:ThemedWindow>

MainWindow.xaml.vb

Imports System.Text
Imports DevExpress.Xpf.Core
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System
Imports System.IO
Imports Microsoft.Win32
Imports System.Windows
Imports System.ComponentModel
Imports DevExpress.Xpf.Grid
Imports System.Windows.Markup
Imports System.Globalization
Imports DevExpress.Data.Filtering

''' <summary>
''' Interaction logic for MainWindow.xaml
''' </summary>
Partial Public Class MainWindow
    Inherits ThemedWindow

    '-------------------Define Product Class--------------------------
    Public Class Product
        Public Property Partnumber As String
        Public Property Opt As String
        Public Property Description As String
        Public Property USD As String

        Public Sub New(PN As String, OP As String, Desc As String, UD As String)

            Partnumber = PN
            Opt = OP
            Description = Desc
            USD = UD
        End Sub

    End Class


    Public Sub New()
        InitializeComponent()

        LoadBound(System.Environment.CurrentDirectory & "\SourceData.txt")
        TopModelDatagrid.ItemsSource = TopProducts
        OptionDatagrid.ItemsSource = OptionProducts
        'InnerGrid.ItemsSource = OptionProducts
        TopModelDatagrid.CurrentItem = TopModelDatagridRowNumber
        OptionDatagrid.Columns(0).AutoFilterValue = TopModelDatagrid.GetCellValue(0, "Partnumber")
        'InnerGrid.Columns(0).AutoFilterValue = OptionDatagrid.GetFocusedRowCellValue("Opt")
        OptionDatagrid.Columns(0).Visible = False
        'InnerGrid.Columns(0).Visible = False

        TopModelDatagrid.Columns(1).Visible = False

    End Sub

    Dim TopProducts As ObservableCollection(Of Product)
    Dim OptionProducts As ObservableCollection(Of Product)
    Dim TopModelDatagridRowNumber As Integer = 0
    Dim OptionDatagridRowNumber As Integer = 0
    Property DatagridFocus As ObservableCollection(Of Boolean) = New ObservableCollection(Of Boolean)

    Private Sub LoadBound(ByVal fName As String)
        'Build a List(Of Product) from the text file
        Dim lstProducts As New List(Of Product)
        Dim lst2Products As New List(Of Product)
        Dim lines = File.ReadAllLines(fName, System.Text.Encoding.Default)
        Dim templine As String
        Dim i As Integer = 0
        For Each line In lines
            i = i + 1
            templine = line

            Dim Props() As String
            Props = templine.Split(CChar(vbTab))

            If Props(0) = Props(1) Then

                Dim p As New Product(Props(0), Props(1), Props(2), Props(3))
                lstProducts.Add(p)
            Else
                Dim p As New Product(Props(0), Props(1), Props(2), Props(3))
                lst2Products.Add(p)
            End If
        Next
        'The constructor of an ObservableCollection can take a List(Of T)
        TopProducts = New ObservableCollection(Of Product)(lstProducts)
        OptionProducts = New ObservableCollection(Of Product)(lst2Products)
    End Sub

    Private Sub TopModelDatagrid_CurrentItemChanged(sender As Object, e As CurrentItemChangedEventArgs) Handles TopModelDatagrid.CurrentItemChanged
        Try
            OptionDatagrid.Columns(0).AutoFilterValue = TopModelDatagrid.GetFocusedRowCellValue("Partnumber")
        Catch ex As Exception
        End Try
    End Sub

    Private Sub OptionDatagrid_CurrentItemChanged(sender As Object, e As CurrentItemChangedEventArgs) Handles OptionDatagrid.CurrentItemChanged
        Try
            'InnerGrid.Columns(0).AutoFilterValue = OptionDatagrid.GetFocusedRowCellValue("Opt")
        Catch ex As Exception
        End Try
    End Sub
End Class

Public Class IsTopModelConverter
    Inherits MarkupExtension
    Implements IValueConverter
    Public Overrides Function ProvideValue(serviceProvider As IServiceProvider) As Object
        Return Me
    End Function

    Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
        Return value.ToString().StartsWith("Topmodel")
    End Function

    Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
End Class

Public Class FilterConverter
    Inherits MarkupExtension
    Implements IValueConverter
    Public Overrides Function ProvideValue(serviceProvider As IServiceProvider) As Object
        Return Me
    End Function

    Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
        Return New BinaryOperator("Partnumber", value)
    End Function

    Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
End Class
导入系统文本
导入DevExpress.Xpf.Core
导入系统集合
导入System.Collections.Generic
导入System.Collections.ObjectModel
导入系统
导入System.IO
导入Microsoft.Win32
导入系统.Windows
导入System.ComponentModel
导入DevExpress.Xpf.Grid
导入System.Windows.Markup
进口系统.全球化
导入DevExpress.Data.Filtering
''' 
MainWindow.xaml的“”交互逻辑
''' 
部分公共类主窗口
继承主题窗口
'--------------定义产品类--------------------------
公共类产品
公共属性Partnumber作为字符串
公共属性选择为字符串
公共属性描述为字符串
公共财产美元作为字符串
公共子新(PN为字符串、OP为字符串、Desc为字符串、UD为字符串)
零件号=PN
Opt=OP
Description=Desc
美元=UD
端接头
末级
公共分新()
初始化组件()
LoadBound(System.Environment.CurrentDirectory&“\SourceData.txt”)
TopModelDatagrid.ItemsSource=TopProducts
OptionDatagrid.ItemsSource=OptionProducts
'InnerGrid.ItemsSource=OptionProducts
TopModelDatagrid.CurrentItem=TopModelDatagridRowNumber
OptionDatagrid.Columns(0.AutoFilterValue=TopModelDatagrid.GetCellValue(0,“零件号”)
'InnerGrid.Columns(0).AutoFilterValue=OptionDatagrid.GetFocusedRowCellValue(“Opt”)
OptionDatagrid.Columns(0).Visible=False
'InnerGrid.Columns(0).Visible=False
TopModelDatagrid.Columns(1).Visible=False
端接头
作为可观察的集合(产品)的Dim TopProducts
变暗选项产品作为可观察的集合(产品)
Dim TopModelDatagridRowNumber为整数=0
Dim OptionDatagridRowNumber为整数=0
属性DatagridFocus作为ObservaleCollection(属于布尔型)=新ObservaleCollection(属于布尔型)
私有子加载绑定(ByVal fName作为字符串)
'从文本文件生成(产品)列表
将产品作为新列表(产品)
Dim LST2产品作为新列表(产品)
Dim lines=File.ReadAllLines(fName,System.Text.Encoding.Default)
暗模板作为字符串
尺寸i为整数=0
每行中的每一行
i=i+1
模板线
Dim Props()作为字符串
道具=模板分割(CChar(vbTab))
如果道具(0)=道具(1),则
Dim p作为新产品(道具(0)、道具(1)、道具(2)、道具(3))
补充(p)
其他的
Dim p作为新产品(道具(0)、道具(1)、道具(2)、道具(3))
lst2Products.Add(p)
如果结束
下一个
'ObservableCollection的构造函数可以获取(T的)列表
TopProducts=新的可观察到的集合(产品)(LST产品)
OptionProducts=新的可观察收集(产品)(LST2产品)
端接头
私有子TopModelDatagrid_CurrentItemChanged(发送方作为对象,e作为CurrentItemChangedEventArgs)处理TopModelDatagrid.CurrentItemChanged
尝试
OptionDatagrid.Columns(0.AutoFilterValue=TopModelDatagrid.GetFocusedRowCellValue(“零件号”)
特例
结束尝试
端接头
私有子OptionDatagrid\u CurrentItemChanged(发送方作为对象,e作为CurrentItemChangedEventArgs)处理OptionDatagrid.CurrentItemChanged
尝试
'InnerGrid.Columns(0).AutoFilterValue=OptionDatagrid.GetFocusedRowCellValue(“Opt”)
特例
结束尝试
端接头
末级
公共类IsTopModelConverter
继承MarkupExtension
实现IValueConverter
作为对象的公共重写函数ProviderValue(serviceProvider作为IServiceProvider)
还我
端函数
公共函数Convert(值作为对象,targetType作为类型,参数作为对象,区域性作为CultureInfo)作为对象实现IValueConverter.Convert
返回值.ToString().StartsWith(“Topmodel”)
端函数
作为对象的公共函数ConvertBack(值作为对象,targetType作为类型,参数作为对象,区域性作为CultureInfo)实现了IValueConverter.ConvertBack
抛出新的NotImplementedException()
端函数
末级
公共类过滤器转换器
继承MarkupExtension
实现IValueConverter
作为对象的公共重写函数ProviderValue(serviceProvider作为IServiceProvider)
还我
端函数
P