|
Hello,
i started building project with Silverlight bussines app.i added EntityModel and Domain Service,in Client side i can see entityobjects (like cars) i can not see CRUD controls(insert,update,delete ) ..
DomainService1 service= new DomainService1
service.insertCar is not shown.
What must i do.
Thanks.
|
|
|
|
|
I would like to do some simple math in my WPF application with as much XAML code as possible and with as little C# code as possible. I have looked at various examples how to do this on diffrent web pages, but they are either to complex or don't show all details or lacks code or is just a bad example.
Please run my XAML code, just copy and paste it:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style x:Key="Alignment">
<Setter Property="Control.HorizontalAlignment" Value="Left"></Setter>
<Setter Property="Control.VerticalAlignment" Value="Top"></Setter>
</Style>
<Style x:Key="GroupBoxStyle" BasedOn="{StaticResource Alignment}">
<Setter Property="Control.BorderBrush" Value="Black"></Setter>
<Setter Property="Control.BorderThickness" Value="2"></Setter>
<Setter Property="Control.FontSize" Value="15"></Setter>
</Style>
<Style x:Key="Header">
<Setter Property="Control.FontSize" Value="15"></Setter>
<Setter Property="Control.FontWeight" Value="Bold"></Setter>
<Setter Property="Control.Height" Value="30"></Setter>
</Style>
</Window.Resources>
<Grid>
<GroupBox Header="Product schedule" Margin="0,0,0,0" Style="{StaticResource GroupBoxStyle}" Width="Auto" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Content="Product" Grid.Row="0" Grid.Column="0" Style="{StaticResource Header}"></Label>
<Label Content="Weight (g)" Grid.Row="0" Grid.Column="1" Style="{StaticResource Header}"></Label>
<Label Content="Numbers" Grid.Row="0" Grid.Column="2" Style="{StaticResource Header}"></Label>
<Label Content="Total weight (g)" Grid.Row="0" Grid.Column="3" Style="{StaticResource Header}"></Label>
<Label Content="A" Grid.Row="1" Grid.Column="0"></Label>
<Label Content="126" Grid.Row="1" Grid.Column="1"></Label>
<TextBox Name="txtA" Grid.Row="1" Grid.Column="2"></TextBox>
<Label Name="lblATotalWeightGram" Grid.Row="1" Grid.Column="3"></Label>
<Label Content="B" Grid.Row="2" Grid.Column="0"></Label>
<Label Content="220" Grid.Row="2" Grid.Column="1"></Label>
<TextBox Name="txtB" Grid.Row="2" Grid.Column="2"></TextBox>
<Label Name="lblBTotalWeightram" Grid.Row="2" Grid.Column="3"></Label>
<Label Content="Total" Grid.Row="3" Grid.Column="0"></Label>
<Label Name="lblPiiGABTotal" Grid.Row="3" Grid.Column="2"></Label>
<Label Name="lblPiiGABTotalWeightGram" Grid.Row="3" Grid.Column="3"></Label>
<Label Name="lblPiiGABTotalWeightKiloGram" Grid.Row="3" Grid.Column="4"></Label>
</Grid>
</GroupBox>
</Grid>
</Window>
Notice I have two Textboxes to specify numbers of product A and product B.
I would like to calculate the following:
1) Total Weight in g for each product: A * 126 and B * 220
2) Calculate total amounth of products: A + B
3) Calculate total weight of all products: (A * 126) + (B * 220)
This should be done if I change any values in the TextBoxes.
Any help would be nice!
|
|
|
|
|
Short answer is "yes, it is possible".
The long answer is a lot less pleasant: it can't be done for free. Pulling this trick requires work. In fact, it requires a lot of work.
Here are the basic steps:
1. First, you need an expression library capable of evaluating expressions presented to it as strings. You can either build one (making a high-performance evaluation library on top of Linq expressions is surprisingly simple), or adopt one written by someone else (for example, this one: Expression Evaluator[^]).
2. Next, you will need to build a Converter class, which is a small adapter for using your expression evaluator in XAML. One class can implement both IMultiValueConverter.aspx[^] and IValueConverter[^], and expose a string property called "Source".
3. Import the assembly with your adapter into your XAML file by adding a clr-namespace referencing your assembly to the Windows element. xmlns:Converter="clr-namespace:MyNamespace.Converter;assembly=MyConverterAssembly"
4. Add a resource for each expression that you would like evaluated from your XAML:
<Converter:ExpressionValueConverter
x:Key="CalcTotalWeight"
Source="(arg1 * 126) + (arg2 * 220)"
/>
5. Use binding or multi-binding to attach your expression to labels and text boxes in your XAML:
<MultiBinding Converter="{StaticResource CalcTotalWeigh}" FallbackValue="0">
<Binding Path="txtA"/>
<Binding Path="txtB"/>
</MultiBinding>
I went through this exercise once, and I can tell you that it is not easy. And I started with a well-tested expression library from step 1! But once you put it all together, it looks like a small miracle.
|
|
|
|
|
Thanks!
Since I'm no master in XAML and I can practically do nothing if I don't have a simple and exact example, your guide will do me no good.
I think I will skip this method and use the old fashion C# way instead. Ugly but easy...
|
|
|
|
|
You could accomplish this entirely in your XAML by using inline code (it's not pretty, and it's not good practice, but it is possible). Basically, you would implement an <x:Code> section where you would put the code in place to handle the calculations, etc. The important thing to remember is that you should encode your code so that you have something that looks like this:<x:Code>
<![CDATA[
// Do your work here
]]>
</x:Code>
|
|
|
|
|
Thanks!
I tried that and it worked. But I don't like the method at all.
|
|
|
|
|
|
Hi,
I want to validate the controls in asp.net silverlight when click a button before save.
We need any validation controls or javascript?
i need to work same as asp.net validation control or javascript validation.
Regards,
YPKI
|
|
|
|
|
Your question does not make sense, you are asking for information about both asp.net and silverlight, in a silverlight forum. Either you are using silverlight or not, decide and then ask a more appropriate question.
You do not use javascript to validate silverlight input, javascript works in conjunction with asp (html) not xaml.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi... I want to distance calculate of a route with Bing Maps in Silverlight 4 (Using VB.Net- NOT C#)
I can calculate a route between two cities but I don't know how many kilometers that ROUTE...I want to learn it... That is important for me...
|
|
|
|
|
Hello again!
I have searched for it but couldn't find an apropriate solution.
I have a list of objects, and I want to arrange them in rows, but still allowing user to select any individual item. For example:
list = { a1, a2,a3,b1,b2,b3}
In a combobox I would like to see:
[ ]V
a1 a2 a3
b1 b2 b3
Items in a combobox are enumeration members and value of a combobox should be bound.
User can select any value from the list. Moreover, items a2,b2,c2,... (that is, when index%3==1 ) should appear in bold (extra feature).
I have tried to set a List<List<MyClass>> as a datasource, but in that case user would be able to set a whole row and not individual items. Such behaviour is unacceptable.
How to accomplish this?
Thanks in advance,
Greetings - Jacek
modified on Sunday, July 31, 2011 6:56 PM
|
|
|
|
|
From MSDN[^] - A ListBoxItem is a ContentControl, which means that it can contain a single object of any type (such as a string, an image, or a panel).
This means you can directly add any type of content you wish (like a grid).
Grid grid = new Grid();
grid.Children.Add(new TextBlock { Text = "Hello"});
listBox.Items.Add(grid);
Or you can use a grid in your ItemTemplate
<ListBox x:Name="listBox" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Property1}" FontWeight="{Binding Path=Property1, Converter={StaticResource fontWeightConverter}}" />
<TextBlock Grid.Column="1" Text="{Binding Property2}" FontWeight="{Binding Path=Property2, Converter={StaticResource fontWeightConverter}}" />
<TextBlock Grid.Column="2" Text="{Binding Property3}" FontWeight="{Binding Path=Property3, Converter={StaticResource fontWeightConverter}}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
listBox.ItemsSource = new MyClass[] {
new MyClass { Property1 = "a1", Property2 = "a2", Property3 = "a3"},
new MyClass { Property1 = "b1", Property2 = "b2", Property3 = "b3"},
new MyClass { Property1 = "c1", Property2 = "c2", Property3 = "c3"},
};
and the FontWeightConverter
public class FontWeightConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
String item = value as String;
if (item == null) return FontWeights.Normal;
int index = int.Parse(item.Substring(1, 1));
return index % 3 == 1 ? FontWeights.Bold : FontWeights.Normal;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Thanks for your answer!
Unfortunately, I don't see how user could select, let say, "a3" in a grid without selecting "a1" and "a2". The list of possible values is flat, and the selection is bound to a single property. User has to choose a single item. Arranging items in a grid is a layout/GUI issue and does not reflect application logic.
Less important: let's say that ther are n columns in a grid. The solution which you have kindly provided fixes n=3. Not so bad since the number of columns will be fixed, but IMHO it is risky and not easily scalable.
Greetings - Jacek
|
|
|
|
|
Actually, a much simpler implementation would be to just swap out the item panel for a WrapPanel. Then you could select individual items...
Simple as 1-2-3...
<ComboBox Height="23" HorizontalAlignment="Left" Margin="177,136,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120">
<ComboBoxItem Content="Item 1" />
<ComboBoxItem Content="Item 2" />
<ComboBoxItem Content="Item 3" />
<ComboBoxItem Content="Item 4" />
<ComboBoxItem Content="Item 5" />
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
|
|
|
|
|
This is what I needed! Thanks very much!
You have a knowledge of the framework.
In this specific scenario, the exact solution is:
<WrapPanel ItemWidth="45" Width="225" />
which gives exactly 5 items in a row, as requested.
Greetings - Jacek
|
|
|
|
|
You're welcome. BTW... forgot to mention the bold thing... you should use the ListBox AlternationCount for the bold feature.
|
|
|
|
|
OK I will try it.
Greetings - Jacek
|
|
|
|
|
I'd pass on this implementation. Too much hard coding of everything.
|
|
|
|
|
Hello!
I have a class:
class MyClass
{
public enum Letters {A,B,C}
public Letters Letter {get;set;}
public bool IsUsed { get; set; }
}
Now, I'd like to bind the Letter property to a Textbox.Text . Works fine, but if a user left the textbox empty, then a parsing error would occur. Instead, in that case I would like to set the IsUsed property to false. I do not want to have a combo box + checkbox, because the enum values are short and well known (like letters) and writing them in a text box is most convenient.
I had tried to bind whole MyClass object and use a converter, but the ConvertBack method didn't have enough data to generate a MyClass object from scratch (there are other members than Letter and IsUsed). I had also tried to pass the original object as a converter parameter but it came out that I cannot bind to ConverterParameter so I am in a dead point.
NOTE: Everything happens in a DataTemplate sandbox for ItemsControl.ItemTemplate , like here:
<DataTemplate x:Key="DataTemplate_Level2">
<TextBox Text="{Binding Path=Letter, Mode=TwoWay}" Width="40" Margin="2" />
</DataTemplate>
How to get it working?
Thanks in advnace
Greetings - Jacek
modified on Saturday, July 30, 2011 4:36 PM
|
|
|
|
|
Making the letter property nullable will fix your paticular issue. But, what if someone types "D"? I would personally use a Selector (like combobox) so the user can choose a valid Letter instead of guessing which letters are valid.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Thanks for answer.
teejayem wrote: Making the letter property nullable will fix your paticular issue.
This would require altering application logic, since the examplary "Letter" property is used in later processing and a new 'null' value would have to be handled. But since it is my own project it is thinkable.
EDIT: No way. It would require too many changes. The enum value is often treated as an integer and sometimes integer arithmetic is used.
teejayem wrote: I would personally use a Selector (like combobox) so the user can choose a valid Letter instead of guessing which letters are valid.
The code which I have posted is purely exmaplary. As I said, actual enum members are known and obvious for a target user. Anyway thanks for a suggestion, I will consider this option.
Greetings - Jacek
|
|
|
|
|
Hi
I have a major problem that is causing me a headache for the last couple of days!
For some reason beyond me my web service isn't working and I am getting the classic error message: "Could not find default endpoint element". My WCF and WPF are in the same solution folder and I am referencing my web service through Service Reference, which generates my app.config. In my WPF I call my web service and pass in via the constructor the name of the end point address. Further, I have copied my app.config to the view layer of my WPF, because my WPF uses MVVM design pattern.
Despite all of this it won't work! Any ideas anyone???
|
|
|
|
|
I had fought with this many times my self. Get firefox. Install firefox and firebug. Use the net tab in firebug to see what is going on.
Did you check the config file of your wpf application? Are the endpoints correct?
Sorry FF may only work with silverlight, not sure about wpf.
I didn't get any requirements for the signature
|
|
|
|
|
Hi,
I have a listbox which is binded to observable collection e.g main menus.
Using DataTemplate I am adding button to each item in list box.
On double click of button in List box, I want to populate the listbox with submenus collection of selected main menu similar to iphone UI.
As I am new to WPF, can anyone suggest me what should I do to meet my requirement.
Also one more problem which I facing is, if I double click button item, that item is not getting selected in list box.
|
|
|
|
|
Hello,
When I click on a button at UI side, One method is called at serviceside(named Service1).
From service1, an asynchronous call given to another service(named Service2).
At same time, callback is returned to UI from Service1.
But I want to wait till Service2 return data to Service1 and stored into database.
Let me know how to wait in asynchronous call.
Thanks in advance.
--
- Parth Gandhi
|
|
|
|
|