小编WAQ*_*WAQ的帖子

动态地将行/列添加到网格中

我有一个孩子,UserControl包括多个文本框,标签,图像等.我需要在具有网格的父用户控件中填充此用户控件.

需要在父用户控件中填充的子用户控件的数量在运行时确定,并且可以更改.基本上,数量取决于搜索结果.所以它可以从0到n.

如何在父控件中填充我的子用户控件?或者是否有更好的替代方法来使用网格控件?

注意:我必须在我的ViewModel中执行此操作.

wpf grid xaml user-controls dynamic

14
推荐指数
1
解决办法
4万
查看次数

在ItemsControl中获取所选项目

我有以下代码以行和列的形式填充我的用户控件.正在填充的用户控件包含按钮,链接,文本框等.当在特定行/列中的特定用户控件上按下某个按钮时,我需要知道该按钮被按下了哪个用户控件.以下是在行和列中填充用户控件的XAML

  <ItemsControl ItemsSource="{Binding Templates}" Width="{Binding GridWidth}">
        <ItemsControl.ItemsPanel>
              <ItemsPanelTemplate>
                    <UniformGrid Columns="{Binding NumColumns}" />
              </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
              <ItemsControl.ItemContainerStyle>
                 <Style>
                     <Setter Property="Grid.Column" Value="{Binding ColumnIndex}" />
                     <Setter Property="Grid.Row" Value="{Binding RowIndex}" />
                  </Style>
                 </ItemsControl.ItemContainerStyle>
                 <ItemsControl.ItemTemplate>
  </ItemsControl>
Run Code Online (Sandbox Code Playgroud)

模板基本上是在行/列中填充的UserControl的集合.我希望在ViewModel中执行此操作,但现在代码中的解决方案也可以正常工作.

wpf xaml binding

11
推荐指数
1
解决办法
3万
查看次数

按钮上的背景图像在鼠标上消失

在我的WPF窗口应用程序中,当我将鼠标移到按钮上时,按钮上的背景图像消失,按钮显示为好像没有任何图像.我想要的是,当鼠标在按钮上时,或者单击按钮时,图像仍然应该显示在按钮上,它不应该消失.

这是我的代码:

 <Button Margin="465, 3, 0, 0" Width="25" Height="20" IsEnabled="True" IsDefault="False" IsCancel="False" BorderBrush="{x:Null}" ToolTip="Reload pads list"> <Button.Background> <ImageBrush ImageSource="/FieldPlanner;component/Images/reload.gif" /> </Button.Background> </Button>
Run Code Online (Sandbox Code Playgroud)

wpf background-image

9
推荐指数
2
解决办法
9336
查看次数

HTTP错误401.0 - 未经授权的错误消息

我开发了一个简单的ASP.Net MVC 4应用程序,使用Windows身份验证在我们公司的本地网络上运行.它在IIS上部署时工作正常.但是,如果我通过Visual Studio运行应用程序,我会收到错误消息

HTTP错误401.0  - 未经授权

这是我的Web.Config文件的样子

<system.web>
<authentication mode="Windows" />
<roleManager defaultProvider="WindowsProvider" enabled="true" cacheRolesInCookie="false">
  <providers>
    <add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
  </providers>
</roleManager>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime maxUrlLength="32767" maxQueryStringLength="32767" targetFramework="4.5" />
</system.web>

 <system.webServer>
<modules>
  <!--<remove name="FormsAuthenticationModule" />-->
</modules>
<security>
  <requestFiltering>
    <requestLimits maxUrl="32767" maxQueryString="32767" />
  </requestFiltering>
</security>
Run Code Online (Sandbox Code Playgroud)

对于调试,应用程序配置为使用"本地IIS Web服务器"运行,并在"应用程序"的"属性" - >"Web"选项卡中选中"使用IIS Express"选项.

c# asp.net iis asp.net-mvc

6
推荐指数
2
解决办法
9830
查看次数

右键单击MVVM,在treeView中选择节点

我想在右键单击中选择树视图的节点.我正在使用MVVM模式,并且不希望在后面的代码中实现这一点.这是我的树视图的XAML.

<TreeView Margin="5,0,0,5"  ItemsSource="{Binding TreePads}">
<TreeView.ItemContainerStyle >
    <Style TargetType="{x:Type TreeViewItem}">
        <Setter Property="IsSelected" Value="{Binding DataContext.IsSelected, Mode=TwoWay,  RelativeSource={RelativeSource Self}}" />
        <Setter Property="ContextMenu">
            <Setter.Value>
                <ContextMenu  DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}" >
                    <MenuItem IsEnabled="{Binding RenameMenuEnabled}" Header="Rename" Command="{Binding RenameCommand}" />
                </ContextMenu>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
            </Trigger>
        </Style.Triggers>
    </Style>
</TreeView.ItemContainerStyle >
<TreeView.Resources>
    <HierarchicalDataTemplate DataType="{x:Type vm:TreePad}" ItemsSource="{Binding Members, Mode=TwoWay}">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding PadName}"/>
        </StackPanel>
    </HierarchicalDataTemplate>
</TreeView.Resources>
Run Code Online (Sandbox Code Playgroud)

wpf treeview xaml

5
推荐指数
1
解决办法
4986
查看次数

在TreeView WPF中向叶节点添加上下文菜单

在我的WPF应用程序中,我想将一个上下文菜单及其处理程序添加ViewModel到我的TreeView控件的叶节点中.这是我添加TreeView控件的方式.

<TreeView Name="treePads" ItemsSource="{Binding pads}" Width="190">
    <TreeView.Resources>
        <HierarchicalDataTemplate DataType="{x:Type self:Pad}" ItemsSource="{Binding Members}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Name}" />
                <TextBlock Text=" [" Foreground="Blue" />
                <TextBlock Text="{Binding Members.Count}" Foreground="Blue" />
                <TextBlock Text="]" Foreground="Blue" />
            </StackPanel>
        </HierarchicalDataTemplate>

        <DataTemplate DataType="{x:Type self:PadInfo}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="["></TextBlock>
                <TextBlock Text="{Binding SlotID}" />
                <TextBlock Text="] ["></TextBlock>
                <TextBlock Text="{Binding WellID}" />
                <TextBlock Text="]"></TextBlock>
            </StackPanel>
        </DataTemplate>
    </TreeView.Resources>
</TreeView>
Run Code Online (Sandbox Code Playgroud)

以下是此代码的输出结果:

我想添加一个ContextMenu有两个选项:Rename,Delete并添加事件处理程序ViewModel.我怎样才能做到这一点?

wpf treeview xaml contextmenu wpf-controls

3
推荐指数
1
解决办法
9667
查看次数

对 ObservableCollection&lt;T&gt; 进行排序

我有两个独立的可观察集合,其中 T 是用户定义的类。这些集合绑定到列表视图和树视图。我想按排序顺序显示集合中的项目。我似乎在列表和树视图上没有找到任何排序功能。集合中的元素可以在运行时删除/添加。实现这一目标的最佳方法是什么?

提前致谢。干杯!

sorting wpf treeview listview observablecollection

2
推荐指数
1
解决办法
4195
查看次数

比较类的属性以确定哪些已更改

在我的 Web 应用程序中,我想在某些内容通过 UI 发生更改时通知用户。例如我的项目类看起来像这样

public class Project
    {
        public string Name { get; set; }
        public TaskStatus Status { get; set; }
        public string Planner { get; set; }
        public DateTime ScheduleStart { get; set; }
        public DateTime ScheduleEnd { get; set; }
        public double EstimatedCost { get; set; }
        public double ActualCost { get; set; }
        public string AssignedTo { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

现在,我已将此信息显示在 UI 上,并且有权更改某些内容(例如状态、计划、成本等)的特定用户可以更改此信息。所以我想要的是,当用户更改某些内容时,应该发送电子邮件以通知项目经理或任何感兴趣的人。

我编写了所有其他所需的代码来发送电子邮件和管理权限等。现在我想具体了解哪些内容发生了变化,例如如果只有 Planner 发生了变化,或者状态发生了变化,那么电子邮件应该包含新值和旧值,就像 TFS 生成通知一样。

PS:上面的代码显示了我的 Project 类的一个非常简单的版本,实际的类有 30 多个属性。所以我在想,不应该对每个单独的属性进行比较,而应该有一种更简单和通用的方法来告诉我哪些属性发生了变化,以便我可以根据它们进行通知。

c# asp.net comparison

2
推荐指数
1
解决办法
3343
查看次数

将上下文菜单命令绑定到ViewModel,该命令不在上下文Visuals树中

我有一个treeView,其itemsource是我的Model类的集合.我在treeView上添加了一个上下文菜单.由于contextMenu的命令应该在可视树中,所以我不得不将它们放在我的Model类中.哪个错误(将模型绑定到目录).

如何将我的上下文菜单的命令绑定到我的ViewModel而不是Model?

谢谢

wpf xaml contextmenu mvvm

0
推荐指数
1
解决办法
2919
查看次数