小编Vis*_*hal的帖子

如何在XAML中设置ItemsSource?

我已经设置了ListBox的ItemsSource,如下所示:

<ListBox ItemsSource="{Binding abc}" />
Run Code Online (Sandbox Code Playgroud)

我想要的是

<ListBox>
    <listBox.ItemsSource>
        ?????????????
    <listBox.ItemsSource>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

wpf xaml

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

MVVM + Mediator模式:Mediator的注册发生得太晚了

我试图在WPF/MVVM应用程序中实现Mediator Pattern,以实现ViewModels之间的通信.

要应用中介模式,我从此链接下载了一个示例项目.然后我从样本中学到了它,然后我申请了我的示例项目.

我对这种模式的使用有一些问题,这反过来会产生荒谬的输出.

让我从我的代码开始:

这是我的项目结构:

SampleWPFMVVMMediatorApp
|
|--Data
|  |--MenuItems.xml
|
|--Extensions
|  |--MediatorX
|  |  |--IColleague.cs
|  |  |--Mediator.cs
|  |  |--Messages.cs
|  |  |--MultiDictionary.cs
|  |--ViewModelBase.cs
|
|--Models
|  |--MenuItem.cs
|
|--ViewModels
|  |--MainWindowViewModel.cs
|  |--ParentMenuViewModel.cs
|  |--ChildMenuViewModel.cs
|  |--SamplePageViewModel.cs
|
|--Views
|  |--ParentMenuView.xaml
|  |--ChildMenuView.xaml
|  |--SamplePage.xaml
|
|--App.xaml
|--MainWindow.xaml
Run Code Online (Sandbox Code Playgroud)

码:

我将发布ViewModels和Models的代码以缩短问题的长度.

MenuItem.cs

public class MenuItem 
{
    public int Id { get; set; }
    public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

MainWindowViewModel.cs

public …
Run Code Online (Sandbox Code Playgroud)

c# wpf mvvm mediator

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

启用和禁用文本框的不同上下文菜单

我有一个文本框。启用后,我会得到一个很好的上下文菜单,其中包含剪切、复制和粘贴。

现在,当 TextBox 被禁用时,我想要一个不同的上下文菜单。我的意思是 contextMenu 应该只有 1 个选项,即复制。

我尝试将文本框包装在网格内,然后在该网格上应用了上下文菜单。但这没有什么区别。还有其他办法吗?

c# wpf

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

如何使用MEF初始化viewModel?

我有一个名为ModuleMenu的模块.在这个模块中,我有一个名为MenuView的UserControl和一个名为UserControlViewModel的Corresponding ViewModel.我还有一个名为Module的类.所有代码如下:

MenuView.xmal

<UserControl ..............>

    <ListBox ItemsSource="{Binding MenuItems, Converter={StaticResource dummy}}" DisplayMemberPath="MenuItemName" SelectedItem="{Binding SelectedMenuItem}" >

        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel IsItemsHost="True" Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>

        <ListBox.Resources>
            <Style TargetType="ListBoxItem">
                <Setter Property="Margin" Value="10,0" />
            </Style>
        </ListBox.Resources>

    </ListBox>

</UserControl>
Run Code Online (Sandbox Code Playgroud)

MenuView.xaml.cs

[Export]
[PartCreationPolicy(CreationPolicy.NonShared)]
public partial class MenuView : UserControl
{
    public MenuView()
    {
        InitializeComponent();
    }
}
Run Code Online (Sandbox Code Playgroud)

UserControlViewModel.cs

[Export]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class MenuViewModel : ViewModelBase
{
    IServiceFactory _ServiceFactory;

    [ImportingConstructor]
    public MenuViewModel(IServiceFactory serviceFactory)
    {
        _ServiceFactory = serviceFactory;
    }

    protected override void OnViewLoaded()
    {
        _MenuItems = new ObservableCollection<MenuItem>();

        WithClient<IMenuItemService>(_ServiceFactory.CreateClient<IMenuItemService>(), menuItemClient => …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml prism mef

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

操作失败:无法更改关系,因为一个或多个外键属性不可为空.

这个问题看起来可能与其他类似问题重复.但我建议你阅读这个问题直到最后,然后决定它是否是一些帖子的副本?????

我的数据库中有6个表,如下所示:

在此输入图像描述

我已经在所有表中插入了一些记录.

现在,我正在尝试更新订单.

起初,我只是尝试按如下方式更新订单:

CurrentOrder.UpdateOrder(Order);
Run Code Online (Sandbox Code Playgroud)

OrderClient中的UpdateOrder方法如下所示:

public Order UpdateOrder(Order Order)
{
    IOrderRepository OrderRepository = _DataRepositoryFactory.GetDataRepository<IOrderRepository>();

    Order updatedEntity = null;

    if (Order.OrderId == 0)
    {
        updatedEntity = OrderRepository.Add(Order);
    }
    else
    {
        updatedEntity = OrderRepository.Update(Order);
    }

    return updatedEntity;

}
Run Code Online (Sandbox Code Playgroud)

在OrderRepository中:

protected override Order UpdateEntity(RateDifferenceContext entityContext, Order entity)
{
    return (from e in entityContext.OrderSet
            where e.OrderId == entity.OrderId
            select e).FirstOrDefault();
}
Run Code Online (Sandbox Code Playgroud)

然后在DataRepositoryBase类中我使用以下方法:

public T Update(T entity)
{
    using (U entityContext = new U())
    {
        T existingEntity = UpdateEntity(entityContext, entity);
        SimpleMapper.PropertyMap(entity, existingEntity);
        entityContext.SaveChanges(); …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework

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

如何在html中调整img标签中使用的svg?

今天,我开始学习SVG并在HTML中使用它.

所以,我在SVG中创建了一个文件,如下所示:

<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     viewbox="0 0 400 200">
    <path d = "M0,100 L100,100 L125,50 L175,150 L225,50 L275,150 L300,100 L400,100"
            style="
                stroke: #000000;
                stroke-width: 5;
                fill: none;
                " 
    />
</svg>
Run Code Online (Sandbox Code Playgroud)

然后我尝试在html中使用它作为图像:

<!DOCTYPE html>
<html>
    <head>
        .....
    </head>
    <body>

        <div class="menu">
            <ul>
                <li class="menu-item"><a href="#"><img src="svg/mysvg.svg" height="48" width="48"></img></a></li>
                <li ...... />
                <li ...... />
                <li ...... />
            </ul>
        </div> 

    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

但我看不到svg没有调整大小.我的错是什么?任何人都能指出我正确的方向吗?

html svg

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

根据vb.net中tablelayout面板中其他控件的可见性更改控件的位置

我在表单中有一个tableLayoutPanel.它包含10个按钮.它们垂直排列如下:

btn1
btn2
btn3
btn4
btn5
btn6
btn7
btn8
btn9
btn10
Run Code Online (Sandbox Code Playgroud)

根据每个按钮的某些属性,一些按钮是可见的,一些是不可见的.

如果btn3,btn5,btn6,btn9是不可见的那么我想安排如下:

btn1
btn2
btn4
btn7
btn8
btn10
Run Code Online (Sandbox Code Playgroud)

但是,我得到的安排不是:

btn1
btn2

btn4


btn7
btn8

btn10
Run Code Online (Sandbox Code Playgroud)

那么我该如何实现目标呢?

vb.net winforms

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

WPF中的自定义控件

我刚刚开始学习WPF.

我有一个带图像的按钮.喜欢Image+Text

    <Button Height="67" Name="Button1" Width="228" HorizontalContentAlignment="Left">
        <StackPanel Orientation="Horizontal" >
            <Image Source="Images/add.png" Stretch="Uniform"></Image>
            <TextBlock Text="  Create Company" VerticalAlignment="Center" FontSize="20"></TextBlock>
        </StackPanel>
    </Button>
Run Code Online (Sandbox Code Playgroud)

现在我想以上述格式添加更多按钮.所以我必须一次又一次地编写相同的代码.

所以我决定让一个customButton轻松完成我的工作.我试图创建自定义控件.

我在那里添加了一个名为Image的属性.现在我应该如何赋予该物业价值?

我走错了路吗?

vb.net wpf button custom-controls

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

从分层Collection中删除项目

我想删除city一个ObservationCollection<City>.

我尝试过的:

private static void DeleteCity(List<City> cities, City cityToDelete)
{
    City nodeToDelete = null;

    foreach (var city in cities)
    {
        if (city.permanentId == cityToDelete.permanentId)
        {
            nodeToDelete = city;
            break;
        }
        DeleteCity(city.Children.ToList(), cityToDelete);
    }
    if (nodeToDelete != null)
    {
        cities.Remove(nodeToDelete);
        return;
    }
}

public static void SomeFunction(...................)
{
    ......
    ......
    ......

    DeleteCity(ServiceLocator.Instance.Cities.ToList(), cityToMove);

    ....
    ....
Run Code Online (Sandbox Code Playgroud)

}

当我return;DeleteCity方法中保持断点时.我可以看到cityToDelete的传入值已从城市中删除.但是当我进一步调用调用函数时,我可以看到ServiceLocator.Instance.Cities仍然持有该特定城市.为什么它不从该集合中删除该城市?

c#

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

为什么 td max-width 在这种情况下不起作用?

这是我的 HTML:

<div class="table-wrapper" ng-app="groupModule">

    <table class="tablify stylable" ng-controller="listController">

        <thead>

            <tr>
                <th>Group Name</th>
                <th>Parent Group</th>
                <th>Effect</th>
                <th class="col-actions">Edit</th>
                <th class="col-actions">Delete</th>
            </tr>

        </thead>

        <tbody>

            <tr ng-repeat="group in groups">

                <td>{{ group.groupName }}</td>
                <td>{{ group.parentGroupName }}</td>
                <td>{{ group.effect }}</td>
                <td class="col-actions">
                    <button type="button" class="btn btn-info btn-edit"></button>
                </td>
                <td class="col-actions">
                    <button type="button" class="btn btn-danger btn-delete"></button>
                </td>

            </tr>


        </tbody>

    </table>

</div>
Run Code Online (Sandbox Code Playgroud)

这是我的 CSS:

.table-wrapper {
  overflow-y: auto;
  height: 75%;
}

table.stylable {
    text-align: center;
    width: 100%;
}

table.stylable th {
    padding: 5px 0;
    text-align: center; …
Run Code Online (Sandbox Code Playgroud)

html javascript css json angularjs

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

标签 统计

c# ×5

wpf ×5

html ×2

vb.net ×2

xaml ×2

angularjs ×1

button ×1

css ×1

custom-controls ×1

entity-framework ×1

javascript ×1

json ×1

linq ×1

mediator ×1

mef ×1

mvvm ×1

prism ×1

svg ×1

winforms ×1