小编Dav*_*mer的帖子

相对于Window的UIElement位置

在WPF中,我想TabControl在我的代码中获取a的角落位置,因此我可以在显示时相应地设置ToolWindow的位置.

我如何获得给定的位置UIElement

buildingInfoWindow = new BuildingInfoWindow(); // BuildingWindow : System.Windows.Window
buildingInfoWindow.Owner = this;

//buildingInfoWindow.Left = ?; // relative X coordinate of my TabControl
//buildingInfoWindow.Top = ?; // relative Y coordinate of my TabControl
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml position uielement

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

WPF:将组合框绑定到类对象的枚举属性?

在命名空间中X,我有一个公共枚举定义:

namespace X
{
    public enum MyEnum
    { val0=0, val1, val2, val3, val4 }
}
Run Code Online (Sandbox Code Playgroud)

在命名空间中,Y我有一个具有该X.MyEnum类型属性的类

using namespace X;
namespace Y
{
    class Container
    {
        public MyEnum MYEnum
        { get { return m_myenum; } set { m_myenum = value; } }

        private MyEnum m_myenum;
    }
}
Run Code Online (Sandbox Code Playgroud)

我创建了一个包含a的用户控件ComboBox.我非常想将它(TwoWay)数据绑定到MYEnum"容器" 的字段.usercontrol驻留在窗口中.

我如何实现这一目标?我见过一些例子ObjectDataProvider,但是我迷路了.

c# data-binding wpf combobox

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

如何遍历WPF工具包Datagrid的行

我有下一个代码,我定义了一个名为dgQuery的WPF工具包数据网格控件; 我用数据集的信息填充了这个,然后我在dgQuery中插入了一个新的复选框列来检查/取消选中某些行,我展示了部分C#代码:

dgQuery.DataContext = dS.Tables[0];

DataGridTemplateColumn cbCol = new DataGridTemplateColumn();
cbCol.Header = "Opc";
FrameworkElementFactory factory = new FrameworkElementFactory(typeof(CheckBox));
Binding bind = new Binding("IsSelected");
bind.Mode = BindingMode.TwoWay;
factory.SetValue(CheckBox.IsCheckedProperty, bind);
DataTemplate cellTemplate = new DataTemplate();
cellTemplate.VisualTree = factory;
cbCol.CellTemplate = cellTemplate;
dgQuery.Columns.Insert(0, cbCol);
Run Code Online (Sandbox Code Playgroud)

在检查/取消选中dgQuery行的新复选框列后,我将单击一个按钮,仅将我检查的行保存到数据库中.问题是,如何开发用于读取dgQuery的所有行的循环以及让我知道哪些行具有选中/取消选中复选框的条件?请帮我举个例子.

谢谢!!

c# wpf datagrid wpftoolkit wpfdatagrid

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

绑定到ItemsControl中的CurrentItem

下面的XAML基本上是尝试创建一个Buttons 列表(从当前集合中Name对象的属性呈现).ViewsDataContext

当我单击按钮时,CurrentItem属性CollectionViewSource应该更改,关联View应该显示在内容呈现器中.

好.如果我点击ListBox下面的XAML,它可以完全按照要求工作.

但是,如果单击UniformGrid(由项目控件创建)中的按钮,CurrentItem则不会更新该属性.

如何CurrentItemItemsControl?中选择项目时更新?

谢谢

<UserControl x:Class="Pos.Features.Reservation.ReservationView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:product="clr-namespace:Pos.Features.ProductBrowser"
             xmlns:activity="clr-namespace:Pos.Features.ActivityBrowser"
             xmlns:addbysku="clr-namespace:Pos.Features.AddBySku"
             xmlns:client="clr-namespace:Pos.Features.ClientBrowser"
             xmlns:notes="clr-namespace:Pos.Features.Notes"
             xmlns:controls="clr-namespace:Pos.Views"
             xmlns:res="clr-namespace:Pos.Core;assembly=Pos.Core"
             Height="300" Width="300">
    <UserControl.Resources>
        <DataTemplate DataType="{x:Type product:ProductBrowserViewModel}">
            <product:ProductBrowserView/>
        </DataTemplate>
        <DataTemplate DataType="{x:Type activity:ActivityBrowserViewModel}">
            <activity:ActivityBrowserView/>
        </DataTemplate>

        <CollectionViewSource x:Name="x" x:Key="ViewsCollection" Source="{Binding Views}"  />
    </UserControl.Resources>

    <StackPanel>
        <ListBox Name="ListBoxMenu" Grid.Column="0" Margin="5" ItemsSource="{Binding Source={StaticResource ViewsCollection}}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" Padding="10"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <ContentControl Grid.Column="1" Content="{Binding …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf itemscontrol collectionviewsource currentitem

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

如何以编程方式在wpf datagrid列中显示图像?

我想在wpf datagrid中动态添加两列一个图像和一个文本列。

XAML代码:

 <Grid><DataGrid AutoGenerateColumns="False" Height="Auto" HorizontalAlignment="Stretch" Margin="0" Name="grid" VerticalAlignment="Stretch" Width="Auto" ></DataGrid></Grid>
Run Code Online (Sandbox Code Playgroud)

背后的代码:

 DataGridTextColumn col = new DataGridTextColumn();
  col.Header =Text1;
  col.Binding =Text1;
  grd.Columns.Add(col);
Run Code Online (Sandbox Code Playgroud)

如何添加图片列?或在该列中显示图片?

请建议

wpf datagrid image

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

WPF - 改变代码背后的样式

我有一个列表框,显示TFS查询的结果.我想在后面的代码中更改ListBoxItem的样式,以获得查询结果中包含的列.

ListBoxItem的样式在我的Windows.Resoruces部分中定义.我试过这个:

public T GetQueryResultsElement<T>(string name) where T : DependencyObject
{
    ListBoxItem myListBoxItem =
        (ListBoxItem)(lstQueryResults.ItemContainerGenerator.ContainerFromIndex(0));

    // Getting the ContentPresenter of myListBoxItem
    ContentPresenter myContentPresenter =
        myListBoxItem.Template.LoadContent().FindVisualChild<ContentPresenter>();

    // Finding textBlock from the DataTemplate that is set on that ContentPresenter
    DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;  <------+
    T myControl = (T)myDataTemplate.FindName(name, myContentPresenter);       |
                                                                              |    
    return (T)myControl;                                                      |
}                                                                             |
                                                                              |
        ContentTemplate is null ----------------------------------------------+
Run Code Online (Sandbox Code Playgroud)

但ContentTemplate为null.我从这里获得了代码,然后使用LoadContent调用对其进行了修改(原始代码为ContentPresenter提供了null).

无论如何.如果你知道改变代码中现有样式的方法,我很乐意看到它.


如果你需要它们的细节:
我将在我的ListBoxItem样式中使用WrapPanel.这就是我想要添加额外的TextBlock项目.

这是我风格的一部分:

<!--Checkbox ListBox-->
<Style x:Key="CheckBoxListStyle" TargetType="ListBox">
    <Style.Resources>
        <Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
            <Setter Property="Tag" Value="{Binding …
Run Code Online (Sandbox Code Playgroud)

c# wpf styles code-behind

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

wpf中的文本框验证

我正在尝试验证文本框以仅输入数字并在wpf中设置最大值和最小值.我想用依赖逻辑做到这一点....任何人都可以帮我一些示例代码或项目吗?

c# validation wpf textbox

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

将一些WPF窗口放入DLL

我有一个WPF项目,并且有一个对话框可以在不同的应用程序中重复使用。我想将其放在自己的DLL中,但是当我在Visual Studio 2008中使用“新建项目”向导时,它只允许我创建WinForm C#DLL。我想念什么吗?

wpf dll window

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

清除可观察集合后 ComboBox SelectedItem 不会更改

ComboBox我遇到了与 a绑定的问题ObservableCollection,我想知道是否有人可以指出我所缺少的内容。

我有一个ComboBox绑定到一个简单的ObservableCollection<string>. 我还将绑定SelectedIndex绑定OneWay到某些属性。

在我的应用程序中,我想要清除集合并用不同的数据重新填充它,并将 设为SelectedIndex新值。由于某种原因,SelectedIndex绑定不起作用。

我附上了这个问题的一些重现:

public partial class Window1 : Window, INotifyPropertyChanged
{
    private int j;
    public event PropertyChangedEventHandler PropertyChanged;

    public Window1()
    {
        InitializeComponent();
        DataContext = this;
        Tables = new ObservableCollection<string>();
    }

    public ObservableCollection<string> Tables { get; set; }

    private int _TheIndex;
    public int TheIndex
    {
        get { return _TheIndex; }
        set
        {
            _TheIndex = value;
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new …
Run Code Online (Sandbox Code Playgroud)

wpf combobox selectedindex selecteditem observablecollection

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

WPF标签控件:设置标签颜色?

TabControl我的WPF应用程序中有一个使用WPF选项卡控件的默认颜色.换句话说,活动选项卡为白色,非活动选项卡为银色.我已经Background通过设置对象的Background属性将所有标签页的颜色更改为Beige TabControl,但它不会更改标签颜色,只会更改客户区.所以,我最终得到了一个活动标签,其中有一个米色客户区和一个白色标签.

我想将标签设置Color为与客户区域匹配,以便整个页面为米色.我该怎么办?谢谢.

wpf tabcontrol colors wpf-controls

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