在ASP.NET MVC项目中为数据库实现Repository时,将业务逻辑放入其中是否正确,或者将逻辑放在控制器类中可能更好?或者使用其他服务和帮助程序类来操作数据?
我有一个奇怪的行为VirtualizingStackPanel.我有一个包含项目的列表TextBlock与TextWrap="Wrap".这是代码:
<ListBox x:Name="messagesList" ItemsSource="{Binding Messages}" >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
...
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<CheckBox Style="{Binding Own, Converter={StaticResource MsgTypeToStyle}}"
Tag="{Binding TimeString}"
IsEnabled="True">
<TextBlock Text="{Binding Content}" TextWrapping="Wrap"/>
</CheckBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但是如果我尝试滚动得非常快(在模拟器上使用鼠标,而不是主要的)滚动中有一些滞后,可能HorizontallOffset有时会计算错误,并且在底部结尾会产生非常奇怪的结果(见图像,右图)说明正常行为).

研究后,我想通了,在组合问题VirtualizingStackPanel及TextBlock.TextWrap="Wrap",如果我从这个夫妻都工作正常删除一个元素.
但我需要虚拟化,因为大项目数量,以及TextWrap正确的文本显示.
所以我考虑自己实现虚拟化面板,请指导我,如何做到这一点,或者如何解决当前的问题?
UPD:问题:
在前两个图像ListBox已经(!)滚动到底部(它不能再向下滚动),但元素放置不正确,正确放置在右图像上.只有在滚动速度非常快时才会发生这种情况.
UPD2:感谢Milan Aggarwal.他在这里提供了一个很好的问题.似乎这真的是一个错误ListBox.提供的解决方法不适合我的方案,因为我需要与ListBox项目内的控件进行交互.现在我正在尝试捕获ManipulationCompleted事件并检查它是否是Inertial,如果是这样意味着滚动并将焦点设置为页面:
void messagesList_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{ …Run Code Online (Sandbox Code Playgroud) 我一般关于渲染管道的问题,我看过ASP.NET MVC管道方案,还有一个名为View Engine的步骤,它是如何工作的?我想知道这种情况:
Response.End()在@{}页面开头的块中使用这个中断执行页面并停止渲染视图?我在WinRT应用程序中使用Caliburn.Micro
这是我的主要VM:
public class MainViewModel : Conductor<Screen>
{
protected override void OnActivate()
{
if (ActiveItem == null)
{
ActivateItem(
ViewModelLocator.LocateForViewType(typeof(NewsFeedView)) as Screen);
}
base.OnActivate();
}
}
Run Code Online (Sandbox Code Playgroud)
这里我使用指挥因为我想在ContentControl中加载不同的控件,但现在我只有这个代码.这是我在主视图中的内容控件:
<ContentControl x:Name="ActiveItem" Grid.Column="1" Grid.Row="1" />
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,一切正常,MainViewModel.Activate被调用并ActiveItem设置NewsFeedViewModel并ContentControl加载NewsFeedView.
问题:
当我在导航NewsFeedView控制,另一种观点认为使用NavigationService.NavigateToViewModel方法,然后在视图中使用NavigationService.GoBack,我就要回MainView在那一刻,当MainViewModel.Activate被称为ActiveItem没有null,但ContentControl.Content就是null.我已经尝试过使用View.Model附属物ContentControl但没有运气,如何让它重新绑定?
编辑: 最后我在Caliburn设置记录器,看看会发生什么,我发现一个错误 - 当导航后加载MainView这个事件发生时:
Attaching ***.Views.MainView to ***.ViewModels.MainViewModel.
ViewModel bound on ActiveItem.
Using …Run Code Online (Sandbox Code Playgroud) 我想获得与文件扩展名相关的程序的路径,最好是通过Win32 API.
UPD:
假设我的办公室安装了office11和office12,.xls的默认程序是办公室11.如果查看HKEY_CLASSES_ROOT\Excel.Sheet.8\shell\Open \命令,有一个office11 excel.exe的路径,但是当我右键单击文件我可以在Open With菜单项中选择office12.那么这个关联存储在哪里?
我正在使用C#.
谢谢.
我正在尝试将实体添加到SQL CE 4,它具有byte []类型的属性.从msdn我已经发现只有图像类型可以容纳大文件(在我的情况下,它们不是那么大,但仍然超过二进制类型8000字节的限制).这是模型:
public class TabModel
{
[Key]
public Guid Id { get; set; }
public string Title { get; set; }
public string Subtitle { get; set; }
public string Artist { get; set; }
public string Album { get; set; }
public string Author { get; set; }
public string TabAuthor { get; set; }
public DateTime DateAdded { get; set; }
[Column("file",TypeName="image")]
public byte[] File { get; set; }
public TabModel()
{
Id = Guid.NewGuid();
DateAdded …Run Code Online (Sandbox Code Playgroud) 如何在视觉树中获得元素的下一个兄弟?这个元素是数据绑定ItemsSource的数据项.我的目标是在代码中访问兄弟(假设我可以访问元素本身),然后使用BringIntoView.
谢谢.
假设我们有一个对象
class Entity
{
public string ID {get; set;}
public string Name {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我想将属性绑定到页面上的两个文本框,如下所示:
<asp:FormView ID="FormView" runat="server">
<ItemTemplate>
<asp:textbox ID="TextId" Text='<%# Bind("ID") %>'/>
<asp:textbox ID="TextId" Text='<%# Bind("Name") %>'/>
</ItemTemplate>
</asp:FormView>
Run Code Online (Sandbox Code Playgroud)
然后在代码后面写这个
public EntityObject
{
get { return ViewState["Entity"] as Entity; }
set { ViewState["Entity"] = value; }
}
protected override void OnInit(EventArgs e)
{
if (EntityObject== null)
EntityObject= new EntityObject();
FormView.DataSource = new[] { EntityObject };
FormView.DataBind();
base.OnInit(e);
}
Run Code Online (Sandbox Code Playgroud)
当我在文本框中输入值时,我希望EntityObject在PostBack之后重新加载页面时在属性中包含这些值,但属性始终为null.
让我们看看这堂课:
public class Cluster
{
private List<Point> points; //private field
public float ComputeDistanceToOtherClusterCLINK(Cluster cluster)
{
var max = 0f;
foreach (var point in cluster.points) // here points field are accessible
{
.......
}
return max;
}
}
Run Code Online (Sandbox Code Playgroud)
为什么我可以访问私人领域?
我可以使用此功能还是可能是不好的做法?
我需要在一个类中组织一些简单的安全性取决于枚举的值.我能想到的只是在方法上使用属性然后运行检查然后如果失败则抛出异常.样品:
[ModulePermission(PermissonFlags.Create)]
public void CreateNew()
{
CheckPermission();
System.Windows.Forms.MessageBox.Show("Created!");
}
protected void CheckPermission()
{
var method = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod();
if (!flags.HasFlag(method.GetCustomAttributes(true).Cast<ModulePermissionAttribute>().First().Flags))
{
throw new ApplicationException("Access denied");
}
}
Run Code Online (Sandbox Code Playgroud)
是否有更优雅或简单的方法来执行此操作,就像在方法运行时触发事件一样?
假设我们有外显:
int? someValue = SomeCondition ? 1 : (int?)null;
Run Code Online (Sandbox Code Playgroud)
所以当SomeCondition为假时,
(int?)null
Run Code Online (Sandbox Code Playgroud)
评估并将成为int的新实例?此时创建的是否已分配给someValue?
这两种变体(性能,内存泄漏或指南)之间是否存在差异?
NPC:
private ICommand mGoBackCommand;
public ICommand GoBackCommand
{
get { return mGoBackCommand; }
set
{
if (mGoBackCommand != value)
{
mGoBackCommand = value;
RaisePropertyChanged("GoBackCommand");
}
}
}
Run Code Online (Sandbox Code Playgroud)
汽车财产:
public ICommand GoBackCommand {get; set;}
Run Code Online (Sandbox Code Playgroud)
UPD:最后一个问题是:我是否可以在VievModel中使用自动属性,如果它们是在构造函数中分配一次的简单命令,或者由于性能,内存泄漏或其他原因我需要在VM的每个属性上实现NPC?
c# ×11
.net ×3
asp.net ×2
asp.net-mvc ×2
wpf ×2
attributes ×1
caliburn ×1
casting ×1
data-binding ×1
methods ×1
mvvm ×1
pipeline ×1
razor ×1
reflection ×1
silverlight ×1
windows ×1
winrt-xaml ×1
xaml ×1