我的问题非常类似于2D背包问题,或切割股票有一个例外......适合容器的矩形可以调整大小和裁剪.但是不允许轮换.
挑战是尽可能少地种植作物并填满整个容器(无任何间隙).
有没有人遇到过类似的算法.任何链接,伪代码非常赞赏.
保持问题通用,但我想应用它来组织固定大小的页面上的照片.
非常感谢
我正在尝试将命令传递给WPF用户控件中的元素.
<UserControl x:Class="MyApp.MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- shortened -->
<Button Command="{Binding Command}">
<Button.Content>
<!-- shortened -->
</Button.Content>
</Button>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
public partial class MyControl : UserControl
{
public static readonly DependencyProperty CommandProperty
= DependencyProperty.Register("Command",
typeof(ICommand), typeof(MyControl));
//shortened
public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
//shortened
}
Run Code Online (Sandbox Code Playgroud)
<uc:MyControl Command="{Binding DoStuffCommand}" /> <!-- shortened -->
Run Code Online (Sandbox Code Playgroud)
单击用户控件中的按钮时,没有任何反应.
当我调试时,该Command属性为null.
将命令绑定到用户控件外部的按钮确实有效.
这里出了什么问题?
我需要在第一行下面插入一个新行.使用下面的代码,我需要添加什么来完成它?
Excel.Application excelApp = new Excel.Application();
string myPath = @"Data.xlsx";
excelApp.Workbooks.Open(myPath);
// Get Worksheet
Excel.Worksheet worksheet = excelApp.Worksheets[1];
int rowIndex = 2; int colIndex = 2;
for (int i = 0; i < 10; i++)
{
excelApp.Cells[rowIndex, colIndex] = "\r123";
}
excelApp.Visible = false;
Run Code Online (Sandbox Code Playgroud)
谢谢 :)
我想动态画一些东西.以下代码显示了我的OnRender.我正在我的程序中的某个地方设置DrawItem,我需要它.但是,当我打电话给DrawItem =5;我必须打电话时,OnRender会被调用吗?
protected override void OnRender(DrawingContext drawingContext)
{
switch (DrawItem)
{
case 1:
//Draw Item
break;
case 2:
//Draw Item
break;
case 3:
//Draw Item
break;
case 4:
//Draw Item
break;
case 5:
//Draw Item
break;
}
base.OnRender(drawingContext)
}
public int DrawItem { get; set; }
Run Code Online (Sandbox Code Playgroud) 我试图将ListView控件绑定到a DataTable,但WPF绑定系统似乎抱怨我指定的绑定路径.
例如,a GridViewColumn定义如下:
<GridViewColumn Header="ColumnTitle"
DisplayMemberBinding="{Binding Path=/,
Converter={StaticResource myConverter}}"/>
Run Code Online (Sandbox Code Playgroud)
据我所知(并且MSN似乎支持我),指定Path=/应该对数据集合的当前项进行绑定.
我收到的错误(在跟踪窗口中)是:
System.Windows.Data错误:39:BindingExpression路径错误:''找不到'当前收集项'''OrdersRow'(HashCode = 680171)'.BindingExpression:路径= /; DataItem ='OrdersRow'(HashCode = 680171); target元素是'TextBlock'(Name =''); target属性是'Text'(类型'String')
这给我的印象/甚至不是一个有效的路径,WPF在斜线后期待一些东西.如果是这样,我将如何绑定到当前项目?为什么我首先得到这个错误?
我试图从我的任务中获取返回数据,如果我使用单个var,它可以正常工作,但是当我使用数组或arraylist时,我在任务对象的可用属性方法中看不到RESULT的接口.
var task = Task<BookingListResponse>
.Factory.StartNew(() => GetServicesFromApi(sc),
TaskCreationOptions.LongRunning);
tasks.Add(task);
try
{
// Wait for all the tasks to finish.
Task.WaitAll(tasks.ToArray());
}
Run Code Online (Sandbox Code Playgroud)
正如你从代码中看到的那样,如果我把任务放回一个数组并输入任务[1] .Result,它不会暴露'结果',如果我访问任务然后我可以得到它.
我确信我做的事情很傻,所以任何帮助都会很好.
干杯.
保罗.
这是完整的代码:
List<Task> tasks = new List<Task>();
// loop schemes and only call DISTINCT transit api URL's
foreach (Scheme scheme in schemes)
{
if (url.ContainsKey(scheme.Url))
continue;
url.Add(scheme.Url, 0); // add url.
var sc = new ServiceCriteria();
sc.Url = scheme.Url;
sc.CapacityRequirement = capacityRequirement;
sc.DropOffLocation = dropOffLocation;
sc.PickUpLocation = pickUpLocation;
sc.PickUp = pickup;
sc.TravelTime = travelTime; …Run Code Online (Sandbox Code Playgroud) 我有以下使用MEF的示例代码:
public interface IFoo<T>
{}
public class Foo<T> : IFoo<T>
{}
[Export(typeof(IFoo<String>))]
public class Foo : Foo<String>
{}
public class Bar<T>
{
[Import]
private readonly IFoo<T> foo;
}
static void Main()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
var container = new CompositionContainer(catalog);
container.ComposeParts();
var bar = new Bar<String>();
//bar.foo would be null
}
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用 - foo领域是null.这是因为MEF看不到它的类型IFoo<String>吗?
我是MVVM模式的新手,我必须在以下视图中拦截已检查/未检查的操作
SendMessageView.xaml
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<CheckBox Checked="Specialita_Checked"
Unchecked="Specialita_Unchecked"
Content="{Binding Path=Item.Name}"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListBoxItem}},
Path=IsSelected,Mode=TwoWay}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
SendMessageView.xaml.cs
private void Specialita_Checked(object sender, System.Windows.RoutedEventArgs e)
{
var aSendMessageViewModel = (SendMessageViewModel)this.DataContext;
if (aSendMessageViewModel != null)
{
var aCheckBox = (CheckBox)sender;
aSendMessageViewModel.AddSpecialita(aCheckBox.Content.ToString());
}
}
Run Code Online (Sandbox Code Playgroud)
aSendMessageViewModel.cs调用的文件是在a内调用SendMessageView.xaml.cs,这是不正确的.帮助我正确使用MVVM模式.
从一起开始使用Typescript和KnockoutJS,我遇到了一个我无法推理的错误.HTML如下所示:
<div class="panel panel-body">
<div class="list-group" data-bind="foreach: Items()">
<a href="#" class="list-group-item"
data-bind="text:Name, click: $parent.SetCurrent">
</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
打字稿如下:
/// <reference path="knockout.d.ts"/>
/// <reference path="jquery.d.ts" />
module ViewModels {
export class ItemViewModel {
public Name: KnockoutObservable<string>;
constructor(name: string) {
this.Name = ko.observable(name);
}//constructor
}
export class MainViewModel {
public SelectedItem: KnockoutObservable<ItemViewModel>;
public Items: KnockoutComputed<Array<ItemViewModel>>;
constructor() {
this.SelectedItem = ko.observable<ItemViewModel>();
this.Items = ko.computed({
owner: this,
read: () => {
return this.get_items();
}
});
}
//TODO: replace this with knockout.mapping plugin transforms
private …Run Code Online (Sandbox Code Playgroud) 我有一个ScrollViewer:
<ScrollViewer Width="160"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Hidden"
Height="324" Canvas.Top="0"
BorderThickness="0" Padding="0">
<ListBox x:Name="Snapshots" SelectionChanged="Snapshots_SelectionChanged"
Padding="0" Background="#FFF0F0F0"
BorderBrush="{x:Null}" VerticalAlignment="Top"
SelectionMode="Single">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding imageSource}"
Margin="5" Stretch="UniformToFill"
Width="120" Opacity="0.2"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"
VerticalAlignment="Top" HorizontalAlignment="Center"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ListBox>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
我该如何实现这些功能:
c# ×4
wpf ×4
algorithm ×1
binding ×1
command ×1
data-binding ×1
drawing ×1
excel ×1
generics ×1
knockout.js ×1
listbox ×1
listview ×1
mef ×1
mvvm ×1
onrender ×1
packing ×1
silverlight ×1
task ×1
typescript ×1