We pay for user submitted tutorials and articles that we publish. Anyone can send in a contribution
Learn MoreWell we’ve arrived at the last part of our series on ASP.NET MVC. In this post we’ll be looking at Views, ViewData, and HTML Helpers. We’ll be discussing how to call Views from Controllers and how to use HTML Helpers to create your markup.
Suppose we receive the following request; http://yourdomain.com/Task/Show/23. The request would map to the following controller.
1: public class TaskController : Controller
2: {
3: public ActionResult Show()
4: {
5: return View();
6: }
7: }
Hi
A while ago Shahar wrote an article about whether WPF Data Binding is Thread safe. Shahar’s findings were that Even if you change a property from a different thread the PropertyChanged event will be called on the UI Thread making Binding Thread Safe.
I have created a Window with 2 TextBlocks, one of them is binded to a Dependency Property and the other is binded to a regular property:
The Window:
1: <StackPanel>
2: <TextBlock Text="{Binding DpTxt}" Width="100" Margin="5"></TextBlock>
3: <TextBlock Text="{Binding Txt}" Width="100" Margin="5"></TextBlock>
4: <Button Content="Change Text" Margin="5" Click="Button_Click"></Button>
5: </StackPanel>
Hi
Where do you locate your convertors? do you put them in the Window.Resources section? or in the UserControl they are being used for? Neither of these options is good. You should put it in the App.Xaml file and here is why:
Lets look at the following example:
Here is our Window:
1: <Window x:Class="ConvertorLocation.Window1"
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: xmlns:my="clr-namespace:ConvertorLocation"
5: Title="Window1" Height="300" Width="300">
6: <Grid>
7: <ItemsControl ItemsSource="{Binding}">
8: <ItemsControl.ItemTemplate>
9: <DataTemplate>
10: <my:UserControl1></my:UserControl1>
11: </DataTemplate>
12: </ItemsControl.ItemTemplate>
13: </ItemsControl>
14: </Grid>
15: </Window>
Hi
Yesterday I was trying to create a control with a partially transparent background,. I am writing this because what I thought was so straight forward, was not.
Here is a simple example:
1: <Grid>
2: <Button Height="23" Margin="94,103,109,0" Name="button1"
3: VerticalAlignment="Top">Button</Button>
4: <Border Margin="57,61,21,101" Name="border1"
5: Background="blue" />
6: </Grid>
When we run this example we will get the following:
Hi.
As the Headline says, I will show you how to make a Drag and Drop / Move Content control. for this example I will use a canvas and an Image. But you can easily make it more generic by using a Content Control instead of the image.
It is actually very simple, let’s start with the Xaml Code.
1: <Canvas Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" HorizontalAlignment="Stretch"
2: VerticalAlignment="Stretch" x:Name="ImageHolder" >
3: <Image Canvas.Left="0" MouseWheel="Img_MouseWheel" MouseMove="Img_MouseMove"
4: MouseDown="Img_MouseDown" MouseUp="Img_MouseUp" Panel.ZIndex="0"
5: Cursor="Hand" Canvas.Top="0" Height="150" Width="150" Source="sketch.jpg"
6: x:Name="Img">
7: </Image>
8: </Canvas>
As you can see we are using a canvas and an Image.
to implement the drag and move we will need to use the following events:
Hi
In my latest article I discussed Scrolling and Binding to large collections in WPF. We saw some disturbing behavior when binding a large collection to an ItemsControl. After Further Examination I found out very interesting things regarding that matter.
We saw that the application used about 500MB of Ram. Lets look at the code again:
We have been looking at all the parts that make a sample ASP.Net MVC application. Previously we have discussed the database schema of our application as well as implementation of the Repository Pattern with filters on that schema. If you haven’t been following this series of posts you might want to read parts 1 and 2 before continuing. Url Routing has become a very common these days. In fact, at least among the websites I visit, it has become more common than not routing urls.
Here we are talking about filtering list items again :). I got two comment suggesting the use of yield return.
James Curran said:
Don’t build a new list if you don’t have to.
private static IEnumerable EvenSlicker_FilterPositiveItems(IEnumerable t)
{foreach(int n in t)
if (n > 0)
yield return n;
}
The advantage is if you try using the method this this:
foreach(int n in FilterPositiveItems(myList) {…}
Your way is O(2N) while mine is O(N)
We all know what breakpoints are, they tell the debugger that an application should break and pause execution, at a certain point. If we want to get certain information at this point, we need to copy it down to a paper or to the notepad. There are breakpoints which get hit hundred of times during the execution of a program, so it may be very exhausting to write down the breakpoint information each time it is hit. Well, last week, while I saw John Cunninghams session at PDC 2008 about Visual Studio Debugger Tips & Tricks, I learned something new. The Visual Studio debugger has another feature called tracepoints.
Hi all
I was into filtering items lately
and I have decided to write about some of the techniques out there starting with the old
Well we have all used this before once you get a list in your hands just iterate through all the items and select the ones you want:
1: private static List<int> TheOld_FilterPositiveItems(List<int> t)
2: {
3: List<int> ret = new List<int>();
4: foreach (int i in t)
5: {
6: if (i > 0)
7: {
8: ret.Add(i);
9: }
10: }
11: return ret;
12: }
I hope you are not using this method. As there are other good methods like this one:
Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd