我正在使用 MVVM 模式在 WPF/c# 中编写表单并尝试与用户控件共享数据。(好吧,用户控件视图模型)
我要么需要:
用户控件仅用于使大型表单更易于管理,所以我不确定这是否是 MVVM 的方式,这正是我过去所做的方式。
我想在 Xaml 中传递一个 VM 构造的类。
<TabItem Header="Applicants">
<Views:ApplicantTabView>
<UserControl.DataContext>
<ViewModels:ApplicantTabViewModel Client="{Binding Client} />
</UserControl.DataContext>
</Views:ApplicantTabView>
</TabItem>
Run Code Online (Sandbox Code Playgroud)
<TabItem Header="Applicants">
<Views:ApplicantTabView>
<UserControl.DataContext>
<ViewModels:ApplicantTabViewModel Client="{Binding Client} />
</UserControl.DataContext>
</Views:ApplicantTabView>
</TabItem>
Run Code Online (Sandbox Code Playgroud)
但我似乎无法获得接受非静态内容的依赖属性。
这对我来说已经有一段时间了,但假设我会发现但失败了,所以我在这里。
提前致谢,奥利
我正在尝试使用此示例设置有效的双向更新。
这些是相关的代码片段:
XAML:
<Button Click="clkInit">Initialize</Button>
<Button Click="clkStudent">Add student</Button>
<Button Click="clkChangeStudent">Change students</Button>
(...)
<TabControl Name="tabControl1" ItemsSource="{Binding StudentViewModels}" >
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=StudentFirstName}" />
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<Grid>
<Label Content="First Name" Name="label1" />
<TextBox Name="textBoxFirstName" Text="{Binding Path=StudentFirstName}" />
<Label Content="Last Name" Name="label2" />
<TextBox Name="textBoxLastName" Text ="{Binding Path=StudentLastName}" />
</Grid>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
Run Code Online (Sandbox Code Playgroud)
主窗口:
public partial class MainWindow : Window
{
internal MainWindowViewModel myMWVM;
public MainWindow()
{
InitializeComponent();
}
private void clkInit(object sender, RoutedEventArgs e)
{
myMWVM= new …Run Code Online (Sandbox Code Playgroud) 我无法理解组合框的行为。
我有一个编辑视图来编辑现有的订单数据。这是我的部分订单数据的 VM:
public class OrderDataViewModel : ViewModelBase, IOrderDataViewModel
{
private readonly ICustomersListProviderService _customersListProviderService;
private readonly Order _order;
public OrderDataViewModel(Order order, ICustomersListProviderService customersListProviderService)
{
Assign.IfNotNull(ref _order, order);
Assign.IfNotNull(ref _customersListProviderService, customersListProviderService);
}
public DateTime CreationDate
{
get { return _order.CreationDate ?? (_order.CreationDate = DateTime.Now).Value; }
set
{
if (_order.CreationDate == value) return;
_order.CreationDate = value;
OnPropertyChanged();
}
}
public Customer Customer
{
get { return _order.Customer; }
set
{
if (_order.Customer == value) return;
_order.Customer = value;
OnPropertyChanged();
}
}
private …Run Code Online (Sandbox Code Playgroud) 我有一个项目,其中有一组要绑定 Canvas 的项目。画布被子类化以提供拖动和调整元素大小的能力。拖动和调整大小的代码工作正常,但问题是我无法绑定画布。我发现我可以做到:
<ItemsControl x:Name="Items" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="1">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controls:SuperCanvas Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding Path=X, Mode=TwoWay}" />
<Setter Property="Canvas.Top" Value="{Binding Path=Y, Mode=TwoWay}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
并且画布被正确绑定并且项目出现在画布上。但是后来我的子类画布不再正常工作。(调整大小和拖动不再起作用。)
这是 SuperCanvas 的代码:
sing System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using Meld.Helpers;
namespace Meld.Controls
{
public class SuperCanvas : Canvas
{
private AdornerLayer aLayer;
private bool isDown;
private bool isDragging;
private double originalLeft;
private double originalTop;
private bool selected;
private UIElement …Run Code Online (Sandbox Code Playgroud) 他们有什么办法可以从哈希码中获取对象吗???
实际上问题是我在我们的应用程序中发现了一些绑定警告,并且每个警告都有相同的源哈希代码。我尝试通过源名称和目标名称进行搜索,但没有找到这样的东西。
所以请帮我找到实际绑定警告即将到来的对象或样式或控制模板?或者帮助我通过其哈希代码找到警告即将到来的对象。
以下绑定警告即将到来。
System.Windows.Media.Animation Warning: 6 : Unable to perform action because the specified Storyboard was never applied to this object for interactive control.; Action='SkipToFill'; Storyboard='System.Windows.Media.Animation.Storyboard'; Storyboard.HashCode='33003048'; Storyboard.Type='System.Windows.Media.Animation.Storyboard'; TargetElement='DevExpress.Xpf.Editors.ErrorControl: DevExpress.Xpf.Grid.GridCellValidationError'; TargetElement.HashCode='56844144'; TargetElement.Type='DevExpress.Xpf.Editors.ErrorControl'
System.Windows.Media.Animation Warning: 6 : Unable to perform action because the specified Storyboard was never applied to this object for interactive control.; Action='SkipToFill'; Storyboard='System.Windows.Media.Animation.Storyboard'; Storyboard.HashCode='33003048'; Storyboard.Type='System.Windows.Media.Animation.Storyboard'; TargetElement='DevExpress.Xpf.Editors.ErrorControl: DevExpress.Xpf.Grid.GridCellValidationError'; TargetElement.HashCode='64558826'; TargetElement.Type='DevExpress.Xpf.Editors.ErrorControl'
System.Windows.Media.Animation Warning: 6 : Unable to perform action because the specified Storyboard was never applied to this object …Run Code Online (Sandbox Code Playgroud) 我想根据节点的宽度订购随机数量的节点。但是我无法计算宽度的总和(使用它们的属性),我有以下示例代码-我无法得知其中一个属性的变化:
@Override
public void start(Stage arg0) throws Exception {
List<SimpleIntegerProperty> l = IntStream.range(0, 10)
.mapToObj(SimpleIntegerProperty::new)
.collect(Collectors.toList());
ObservableList<IntegerProperty> widthAr = FXCollections.observableArrayList();
widthAr.addAll(l);
IntegerBinding nextheight = Bindings.createIntegerBinding(() -> widthAr.stream()
.mapToInt(IntegerProperty::get)
.sum(), widthAr);
nextheight.addListener((v, o, n) -> System.out.println("New value: " + v.getValue()));
//Now change randomly one of the IntegerProperties
ScheduledExecutorService tfsqueryScheduler = Executors.newScheduledThreadPool(1);
tfsqueryScheduler.scheduleAtFixedRate(() -> {
System.out.println("Changing");
int i = (int) Math.round(Math.random() * 9.4);
SimpleIntegerProperty v = l.get(i);
v.set(0);
}, 0, 3, TimeUnit.SECONDS);
System.out.println("Start...");
}
Run Code Online (Sandbox Code Playgroud)
再也不会调用nextheight.addListener :( ...有什么想法吗?谢谢!
我试图开发一个应用程序,我想使用路由绑定,但出了点问题,我不知道是什么。Plz,看看下面的代码,帮我看看哪里出了问题。
路线
| | PATCH | api/v1/filial/{filial} | | Genesis\Base\Filial\Controllers\FilialController@update | auth:api |
Run Code Online (Sandbox Code Playgroud)
模型
class Filial extends Model{
/**
* @var string
*/
protected $table = "filiais"; ...
Run Code Online (Sandbox Code Playgroud)
控制器
class FilialController extends BaseFormController{...
public function update(FilialRequest $request, Filial $filial){
dd($filial);
}...
Run Code Online (Sandbox Code Playgroud)
然后输出是一个空模型。我不知道这是什么错误,参数的,模型的,Uri 所有这些都匹配。我从这个项目开始就使用 Laravel 5.6。
我有Label和的形式Slider.
我试图Label.Content通过从ViewModel属性获取值来进行更改.另外,我在ViewModel中使用更新该值Slider,但是当我更改滑块值时,属性更新,但我看不到更新的值Label.Content拥有该值,这是在运行程序之后.
xaml代码:<Slider
Value="{Binding MathLevel, Mode=TwoWay}"
Width="200" />
<Label
Content="{Binding MathLevel}"
HorizontalAlignment="Left"
Margin="157,250,0,0"
VerticalAlignment="Top" />
Run Code Online (Sandbox Code Playgroud)
public int MathLevel
{
get => user.Skills [0].Level;
set {
user.Skills [0].Level = value;
OnPropertyChanged("Math skill level");
}
}
Run Code Online (Sandbox Code Playgroud)
class User
{
public List<Skill> Skills {get;set;} = new List<Skill>();
}
Run Code Online (Sandbox Code Playgroud)
我只是想改变Content就Label从属性值MathSkill
UnsupportedOperationExceptionBindings.bindContent()将对象绑定到时抛出TableView。为什么?如何解决这个问题?
我正在使用Java 8 update181。
Exception in Application start method java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(AbstractList.java:161)
at java.util.AbstractList$Itr.remove(AbstractList.java:374)
at java.util.AbstractList.removeRange(AbstractList.java:571)
at java.util.AbstractList.clear(AbstractList.java:234)
at com.sun.javafx.binding.ContentBinding.bind(ContentBinding.java:55)
at javafx.beans.binding.Bindings.bindContent(Bindings.java:1020)
at problem_bind.Main.start(Main.java:42)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294) …Run Code Online (Sandbox Code Playgroud) binding javafx tableview invocationtargetexception unsupportedoperation
呈现原始html时如何使用动态属性和绑定。假设:
<script>
let name = 'Joseph'
let test = '<p>{name}</p>'
</script>
{@html test} <!-- Outputs: {name} instead of Joseph -->
Run Code Online (Sandbox Code Playgroud)
我知道,有人会回答,一种更好的方法是创建一个组件。但是我仍然想问,是否有一种在原始html渲染中使用绑定的方法?
binding ×10
wpf ×6
mvvm ×4
c# ×3
javafx ×2
combobox ×1
eloquent ×1
hashcode ×1
javascript ×1
laravel ×1
php ×1
properties ×1
selecteditem ×1
storyboard ×1
svelte ×1
tableview ×1