在WPF DataGrid上禁用行编辑 [英] Disable row edit on WPF DataGrid

查看:849
本文介绍了在WPF DataGrid上禁用行编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里需要帮助。我正在尝试禁用WPF DataGrid上的某些行编辑。
这是我的XAML:

 < DataGrid ItemsSource = {Binding Path = Combustibles} AutoGenerateColumns = False  SelectedItem = {Binding Path = SelectedCombustible}> 
< DataGrid.Resources>
< Style TargetType = {x:Type DataGridRow}>
< Style.Triggers>
< DataTrigger Binding = {Binding IsReadOnly} Value = True>
< Setter Property = IsEnabled Value = False />
< / DataTrigger>
< /Style.Triggers>
< / Style>
< /DataGrid.Resources>
< / DataGrid>

这是我的ViewModel:

 公共类CombustiblesViewModel:BaseViewModel 
{
public List< CombustiblesWCFModel>可燃物{得到;组; }

私人CombustiblesWCFModel _selectedcombustible = new CombustiblesWCFModel();

public CombustiblesViewModel()
{
Combustibles = _svc.Combustibles_List(sTicket);
可燃物品[1] .IsReadOnly = true;
}

public CombustiblesWCFModel SelectedCombustible
{
get
{
返回此。
}

set
{
this._selectedcombustible = value;
NotifyOfPropertyChange( SelectedCombustible);
}
}
}

我的模型有一个属性:

 公共部分类CombustiblesWCFModel 
{
public Boolean IsReadOnly {get;组; }
}

因此,应该禁用第1行进行编辑还是不是? / p>

我的Finaly计划是手动开始行编辑(每行带有一个链接),并通过每行上的另一个链接确认行编辑,以使用WCF服务保存数据。 / p>

解决方案

您可以手动定义列

 < DataGridTemplateColumn> 
< DataGridTemplateColumn.CellTemplate>
< DataTemplate>
< TextBox Text = {Binding Path = YourField}
IsReadOnly = {Binding IsReadonly} />
< / DataTemplate>
< /DataGridTemplateColumn.CellTemplate>
< / DataGridTemplateColumn>

希望这会有所帮助


I need help here. I'm trying to disable some rows edit on a WPF DataGrid. This is my XAML:

<DataGrid ItemsSource="{Binding Path=Combustibles}" AutoGenerateColumns="False" SelectedItem="{Binding Path=SelectedCombustible}">
    <DataGrid.Resources>
        <Style TargetType="{x:Type DataGridRow}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsReadOnly}" Value="True" >
                    <Setter Property="IsEnabled" Value="False" />                                
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.Resources>
</DataGrid>

And this is my ViewModel:

public class CombustiblesViewModel: BaseViewModel
{        
    public List<CombustiblesWCFModel> Combustibles{ get; set; }

    private CombustiblesWCFModel _selectedcombustible = new CombustiblesWCFModel();

    public CombustiblesViewModel()
    {
        Combustibles = _svc.Combustibles_List(sTicket);
        Combustibles[1].IsReadOnly = true;
    }            

    public CombustiblesWCFModel SelectedCombustible
    {
        get
        {
            return this._selectedcombustible;
        }

        set
        {
            this._selectedcombustible = value;
            NotifyOfPropertyChange("SelectedCombustible");                
        }
    }
}

My Model has a Property:

public partial class CombustiblesWCFModel
{
    public Boolean IsReadOnly { get; set; }
}

So, Row 1 should be disable for edditing or isn't?

My Finaly boal is to manually start row edit (With a link on each row) and confirm row edit with another link on each row to save data using a WCF services.

解决方案

You could define your columns manually

<DataGridTemplateColumn>
   <DataGridTemplateColumn.CellTemplate>
       <DataTemplate>
           <TextBox Text="{Binding Path=YourField}" 
                    IsReadOnly="{Binding IsReadonly}"/>
       </DataTemplate>
   </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Hope this helps

这篇关于在WPF DataGrid上禁用行编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆