 |

|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|

|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|

|
Using the default MVVM light project for Windows Phone, I tried to implement a databinding to a ListBox. Unsuccessfully. The same CS code, placed in the normal code behind seems to bind just fine. But over in the view model, I get nothing but a blank box.
<ListBox x:Name="myListBox" HorizontalAlignment="Left" Height="100"
VerticalAlignment="Top" Width="200">
<ListBox.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding theList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Width="auto">
<TextBlock Text="{Binding Path=Key}" />
<TextBlock Text="{Binding Path=Value}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
public Dictionary<string, string> theDictionary;
private List<Dictionary<string, string>> _theList;
public const string theListPropertyName = "theList";
public List<Dictionary<string, string>> theList
{
get
{
return _theList;
}
set
{
if (_theList == value)
return;
_theList = value;
RaisePropertyChanged(theListPropertyName);
}
}
public MainViewModel(IDataService dataService)
{
List<Dictionary<string, string>> x = new List<Dictionary<string, string>>();
theDictionary = new Dictionary<string, string>();
theDictionary.Add("1", "A");
theDictionary.Add("2", "B");
theList = new List<Dictionary<string, string>>();
theList.Add(theDictionary);
}
|
|
|
|

|
Set the items source property of the listbox to your list ("theList") not the items source property of item template.
<ListBox x:Name="myListBox" HorizontalAlignment="Left" Height="100" ItemsSource="{Binding theList}" VerticalAlignment="Top" Width="200">
|
|
|
|

|
Thanks Amitosh, but I think there must be more to it.
I still don't see any data from the ViewModel with an additional ItemsSource={"Binding theList"} on the listbox declaration.
Maybe this is useful: I pulled a reference to the ViewModel in the code behind. I manually assigned myListBox.ItemsSource=vm.theList, and the data appeared!
As to why the one bound through MVVM doesn't work, still a mystery.
modified 1 hr ago.
|
|
|
|

|
I agree, I took me a week to understand MVVM architecture, yet not perfectly. I still get weird errors!
Where did you initialize the view model in the code behind or xaml?
Viewmodel should be set as the data context of the root element (window,page,usercontrol... etc).
|
|
|
|

|
Hi,
i have a datagrid implemented in xaml like this:
<DataGrid ItemsSource="{Binding Stuff}" HeadersVisibility="None" GridLinesVisibility="None" AutoGenerateColumns="True" Height="500" Margin="72,363,72,-3" Name="myGrid" VerticalAlignment="Top" Background="{x:Null}" RowBackground="{x:Null}" CanUserAddRows="True" FontSize="20" /><pre lang="xml">
The grid is automatically populated (via a Binding) with two columns and some data. All is well but the text in the columns is left-aligned.
Is it possible to force the text in one of the autogenerated columns to be right-aligned?
Regards
|
|
|
|

|
You should be able to do this by applying a style to the DataGridColumnHeader. Off the top of my head, the following should do it:<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" HorizontalAlignment="Right" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
|
|
|
|

|
Hi and thanks for the reply.
Unfortunately that did not do the trick. The column headers are hidden so i do not need to right-align them.
Basically the datagrid has two columns of data. I need the DATA in ONE of the columns to be right aligned.
I tried this:
<Style TargetType="DataGrid">
<Setter Property="CellStyle">
<Setter.Value>
<Style TargetType="DataGridCell">
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
</Setter.Value>
</Setter>
</Style>
but that just plain righ-aligns everything in the datagrid (data in column 1 and in column 2). Is it possible to apply this to column 2 only?
Note that i do not have the column definitions in my xaml since the datagrid is populated via a binding.
Thanks
|
|
|
|

|
You can use the AutoGeneratingColumn event to handle this. Source[^].
|
|
|
|

|
I have created a SilverLight application that uses ADO and DomainServices to populate a DataGrid from an SQL 2008 database server. The context looks like this
EcDomainContext context1 = new EcDomainContext();
A few months later, I added a table to the database so in order to use this new table, I had to rebuild as follows:
-deleted all MyDomainServices (.cs) files
-deleted the Mymodel (.edmx) file
-recreate by adding the ADO and Domainservices again
-reconfigure the MyDomainServices.cs as before.
Well, I just added another table and I would like to know if there is an easier way to do this?
Many thanks.
Ps
|
|
|
|

|
hi i have made the stickin which i am moving a small box around it using motion path. but when i change the angle of that stick through slider, the box movement "animation" still remains same the original path which i set the default. is there any way i can change its animation by depending on its angle.
|
|
|
|

|
When working with a XAML file in conjunction with JavaScript and HTML in VisualStudio, whenever I try to set the Loaded attribute in my Grid, my XAML page will fail to load. I get a blank screen and when I right click somewhere in the page, I see a little box saying 'Silverlight'. The JavaScript will also fail to execute.
I get the following message when I try to open the page in Internet Explorer: "Must compile XAML that specifies events".
Surprisingly, the other XAML page (Speeds.xaml) I have does not fail to execute the JS nor the XAML. It runs properly.
Failing XAML file (Accuracy.xaml):
="1.0" ="UTF-8"
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
="http://schemas.microsoft.com/winfx/2006/xaml"
="onLoaded"
="20*"
="60*"
="20*"
="20*"
="60*"
="20*"
="#FF3B596E"
="#FF93C5E8" ="1"
="1" ="1"
="#FF93C5E8"
="#FF3B596E" ="1"
="Ivory" ="16" ="369.68" ="22.29017076"
="103.03999999999999" ="103.03999999999999" ="75.76162307999999" ="2" ="Red" ="26.73572616"
="Sum 1-20" ="Ivory" ="Center" ="Center"
="103.03999999999999" ="357.6" ="75.76162307999999" ="2" ="Red" ="26.73572616"
="Sum 21-40" ="Ivory" ="Center" ="Center"
="103.03999999999999" ="612.1600000000001" ="75.76162307999999" ="2" ="Red" ="26.73572616"
="Sum 41-60" ="Ivory" ="Center" ="Center"
="48.480000000000004" ="154.9844" ="758.24" ="154.9844" ="2" ="Red"
="48.480000000000004" ="154.9844" ="48.480000000000004" ="333.6304" ="2" ="Red"
="48.480000000000004" ="200.5612596" ="758.24" ="200.5612596" ="1" ="Red"
="48.480000000000004" ="245.1381192" ="758.24" ="245.1381192" ="1" ="Red"
="48.480000000000004" ="289.7149788" ="758.24" ="289.7149788" ="1" ="Red"
="48.480000000000004" ="334.29183839999996" ="758.24" ="334.29183839999996" ="1" ="Red"
="24.240000000000002" ="148.42759999999998" ="15" ="Center"
="0" ="Ivory" ="Center"
="24.240000000000002" ="193.0044596" ="15" ="Center"
="5" ="Ivory" ="Center"
="24.240000000000002" ="237.5813192" ="15" ="Center"
="10" ="Ivory" ="Center"
="24.240000000000002" ="282.1581788" ="15" ="Center"
="15" ="Ivory" ="Center"
="24.240000000000002" ="326.73503839999995" ="15" ="Center"
="20" ="Ivory" ="Center"
="96.88" ="154.9844" ="#FF0093DD" ="30.320000000000004" ="116.1199" ="Collapsed" ="bar0" ="test"
="13" ="Ivory" ="Center" ="Bottom"
="145.35999999999999" ="154.9844" ="#FF29166F" ="30.320000000000004" ="35.7292" ="Collapsed" ="bar1" ="test"
="4" ="Ivory" ="Center" ="Bottom"
="193.84" ="154.9844" ="#FF830F0F" ="30.320000000000004" ="26.7969" ="Collapsed" ="bar2" ="test"
="3" ="Ivory" ="Center" ="Bottom"
="345.36" ="154.9844" ="#FF0093DD" ="30.320000000000004" ="53.5938" ="Collapsed" ="bar3" ="test"
="6" ="Ivory" ="Center" ="Bottom"
="393.84000000000003" ="154.9844" ="#FF29166F" ="30.320000000000004" ="80.3907" ="Collapsed" ="bar4" ="test"
="9" ="Ivory" ="Center" ="Bottom"
="442.32" ="154.9844" ="#FF830F0F" ="30.320000000000004" ="44.6615" ="Collapsed" ="bar5" ="test"
="5" ="Ivory" ="Center" ="Bottom"
="593.84" ="154.9844" ="#FF0093DD" ="30.320000000000004" ="107.1876" ="Collapsed" ="bar6" ="test"
="12" ="Ivory" ="Center" ="Bottom"
="642.32" ="154.9844" ="#FF29166F" ="30.320000000000004" ="26.7969" ="Collapsed" ="bar7" ="test"
="3" ="Ivory" ="Center" ="Bottom"
="690.8000000000001" ="154.9844" ="#FF830F0F" ="30.320000000000004" ="44.6615" ="Collapsed" ="bar8" ="test"
="5" ="Ivory" ="Center" ="Bottom"
="96.96000000000001" ="378.87690204" ="#FF0093DD" ="200.0" ="31.19970204"
="N° of correct responses" ="Ivory" ="Center" ="Center"
="296.96000000000004" ="378.87690204" ="#FF29166F" ="200.0" ="31.19970204"
="N° of incorrect responses" ="Ivory" ="Center" ="Center"
="496.96000000000004" ="378.87690204" ="#FF830F0F" ="200.0" ="31.19970204"
="N° of no responses" ="Ivory" ="Center" ="Center"
Working XAML (Speeds.xaml):
="1.0" ="UTF-8"
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
="http://schemas.microsoft.com/winfx/2006/xaml"
="onLoaded"
Why is this happening and how can I fix this?
modified 3 days ago.
|
|
|
|

|
Yes you have the answer, you must compile XAML to BAML in order to use events!
This is what that is done while compiling an app in visual studio. I guess you are trying with an XAML browser project??
|
|
|
|

|
No, I do not have the answer. The problem is not 'Must compile XAML that specifies events'.
The problem is that Visual Studio does not accept XAML files that have Elements whose Background property is set. On my machine it is not compatible with the Background property for some reason. After I set any Background property on my XAML page and I run my project, Visual Studio will show a white page in my Accuracy.html. Everything is white. No content. I am trying to understand why Visual Studio does not accept this Background property.
|
|
|
|

|
Strange?? I do files with a great deal of backgrounds with fancy gradients, images... designed with blend of course??
Well mine is vs2012? yours??
|
|
|
|

|
Hi,
Is this okay to use Frame control in my Main window to load a Xaml page at Runtime?
It also has to support drag/drop feature so that users can drag a control from Toolbox of Main window to the Xaml page in the Frame.
Please suggest/explain.
Thanks.
Be a good professional who shares programming secrets with others.
|
|
|
|

|
You can directly load the view into the user control.
|
|
|
|

|
Whether user control supports drag/drop?
Be a good professional who shares programming secrets with others.
|
|
|
|

|
Hi, I have a treeview where the nodes are generated on runtime.
I want to drag the child node into a canvas a generate an image for each node.
My scenario is i want to allow only certain node to be able to drag and only allow dragging when user want to edit the canvas. How should i achieve that?
Currently I'm using the Silverlight Toolkit TreeViewDragDropTarget.
|
|
|
|

|
I have been working on a project that uses user controls inside other views. What I still can't figure out is how to get a reference to the user control's ViewModel so I can get data off of it or write data to it.
So far, I have been getting a reference to the user control, then getting the VM as the DataContext, then accessing it through that refereence. But this doesn't seem to be right.
In another project I'm using a factory pattern in my AppResources.XAML, such as:
<DataTemplate DataType="{x:Type vm:ClientCenterViewModel}">
<vw:ClientCenterView/>
</DataTemplate>
This does a nice job of pairing the VM to the View, but I can't get a reference to the view's VM to read/write to it.
What's the right way to do this?
Thanks
If it's not broken, fix it until it is
|
|
|
|

|
You shouldn't need to have access to a child controls VM directly. It's all done via data binding. <Window> <Grid> <MyChildView SomeProp="{Binding SomeProp}" /> </Grid> </Window> If you are using DataTemplates to map views <-> VMs, you also don't need access to the VM directly because those views should operate on thier own VMs which would talk to the persistance layer directly. If you are finding that you need to access a child control/view to do stuff from the code behind, its probably because you didn't expose that functionality with a bindable property. If you don't own the code of the child view, you can expose the functionality you need with a bindable attached behavior.
|
|
|
|

|
Ok, I'm not sure I understand.
In this case I have a Materials view, and on it is a control that lists prices. The prices control is used in more than one view which is why it's a control.
There is a one to many between Materials and Prices, so the prices view needs to know the PK of the Material. In addition, the Material needs to know the count of Prices and other info.
When a material is selected I need to tell the prices view the PK of the selected material so it can load them. When a price is added to the list in the Prices control, the Material view needs to know it.
The Prices control already handles it's own CRUD operations, but I don't understand how it and the Materials view are supposed to intertact. There has to be some way to say "Hey Prices view, give me your data" or, "Hey Prices view, load the prices for this Material".
Using Data Templates to map them seems to make it impossible since the VM for the Materials has no clue that there's a Prices control any where.
If it's not broken, fix it until it is
|
|
|
|

|
Yeah, so its like what I said. Assuming I get what you are talking about . Psuedo-code: <Window> <MaterialView /> </Window> <MaterialView> <ListView Name="lv" ItemsSource="{Binding ListOfMaterials}" /> <PriceControl Source="{Binding ElementName=lv, Path=SelectedItem.PK}" /> </MaterialView> Then your PriceControl would auto-magically know when a different material has been selected. But it needs to expose a property that can be data-bound. EDIT: I just noticed in your response that you wanted to go both ways, so you can do something like: <MaterialView> <Label Content="{Binding ElementName=pc, Path=Count" /> </MaterialView> You just need to expose everything you want to transfer back and forth as a property in the VMs. The key here is to use the ElementName binding.
|
|
|
|

|
I see. Thanks!
If it's not broken, fix it until it is
|
|
|
|

|
Hello Listeners,
Working on a silverlight application. The data that needs to be returned is very small (1-4 rows)
My domainservice includes following code to populate a datagrid
public IQueryable GetProductsFiltered(int vendorId)
{
return this.ObjectContext.Products.Where(P => P.VendId == vendorId);
}
When the correct value is provided via a “GetProductsFilteredQuery(2)”, the server returns the data and datagird is properly populated.
Now I need to return data based on a column named SiteID so I added another method
public IQueryable GetProductsFilteredSite(int siteId)
{
return this.ObjectContext.Products.Where(P => P.SiteID == siteId);
}
And call it by something like this “GetProductsFilterSiteQuery(5)” . Compiles fine but but error is generated when running the application:
“Local operation failed for query “ GetProductsFilterSite”. The remote server returned an error: NotFound”.
Run the query manually –OK
Fiddler also logs an 504 error “ReadResponse() failed: The server did not return a response for this request.”
But also shows a valid argument passed to GetProductsFilterSiteQuery() method
Any idea is greatly appreciated
|
|
|
|

|
You can try out two things -
1) If you are deploying your service on IIS, you will need to redeploy after adding the new method.
2) You will need to update your service proxy. If you added the website manually, then just right click on the service and refresh.
|
|
|
|

|
Re-publishing the domain services solved my problem.
Many thanks for the help Abhinav
|
|
|
|

|
How to achieve the below layout ? I am new to Silverlight. I need to achieve the same with Paging. Which one is better DataGrid or ListBox ? Can i achieve the same with normal Silverlight but with paging? I dn't want a column header and also my row should have the details filled with Image,Links,Text etc as below...
I want to achieve the same Layout as given in the link http://demos.devexpress.com/AgDataGridDemos/ under the Customization/Row Template tab with Filtering,Sorting and paging functionalities using normal Silverlight Controls. I have to hide the Headers also.
Note: In the example,u can see only Rowtemplate.I wanna acheive exactly same Layout.Go to Link and Click Customization/Row Template tab
|
|
|
|

|
Since you use a number of features like filtering and sorting, you could go for a grid rather than a listbox.
If you want to go for light code and avoid a heavy grid loading on your page, you could still consider using the listbox and build sorting and filtering features into it.
|
|
|
|

|
I have a SL application that I have been working. Make little changes and save a back up so I can roll it back if a problem so I have a few backups.
Today I open the project and the page generated an error. Although I can compiled successfully, the error is when I view page in designer. “ ArgumentException was thown on parameter”: The myMethod method does not have an argument that matches the querParameter collection”.
Then I tried to load a previous project and shows the same thing, as of matter of fact, all of them have the same problem now. What a…!!!
Problem points to
<riaControls:Parameter ParameterName="argType" Value="{Binding ElementName=argTypeTextBox, Path=Text}" />
The code is below. Any help is greatly appreciated
<navigation:Page x:Class="EclipseMTX.Views.Protons"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="1200" d:DesignHeight="724"
Title="Protons Page" BorderBrush="#FF834F4F" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices" xmlns:my="clr-namespace:EclipseMTX.Web">
<Grid x:Name="LayoutRoot" Background="#FF0E0E0E" Width="1196" Height="728">
<sdk:DataGrid AutoGenerateColumns="True" AutoGeneratingColumn="DGPro_AutoGeneratingColumn" Height="263" HorizontalAlignment="Left" Margin="135,86,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="1049" Background="#F3333333" Foreground="WhiteSmoke" RowBackground="#F3333335" VerticalScrollBarVisibility="Disabled" />
<sdk:Label Height="45" HorizontalAlignment="Left" Margin="439,28,0,0" Name="label1" VerticalAlignment="Top" Width="324" Content="Proton Installed base" Foreground="WhiteSmoke" FontSize="28" />
<sdk:DataPager Height="26" HorizontalAlignment="Left" Margin="135,347,0,0" Name="dataPager1" PageSize="10" VerticalAlignment="Top" Width="1051" Background="#F3333333" Cursor="Hand" Foreground="WhiteSmoke" />
<Button Content="Run Query" Height="23" HorizontalAlignment="Left" Margin="19,355,0,0" Name="button1" VerticalAlignment="Top" Width="102" Click="button1_Click" />
<riaControls:DomainDataSource AutoLoad="False" d:DesignData="{d:DesignInstance my:Proton, CreateList=true}" Height="0" LoadedData="protonDomainDataSource_LoadedData" Name="protonDomainDataSource" QueryName="GetProtonsFiltered" Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:EclipseMTXDomainContext />
</riaControls:DomainDataSource.DomainContext>
<riaControls:DomainDataSource.QueryParameters>
<riaControls:Parameter ParameterName="argType" Value="{Binding ElementName=argTypeTextBox, Path=Text}" />
</riaControls:DomainDataSource.QueryParameters>
</riaControls:DomainDataSource>
<StackPanel Height="30" HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Top"></StackPanel>
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="19,58,0,0" Name="label3" VerticalAlignment="Top" Width="120" Content="By Vendor" Foreground="WhiteSmoke" FontSize="18" />
<sdk:DataGrid AutoGenerateColumns="True" AutoGeneratingColumn="DGPCSN_AutoGeneratingColumn" Height="265" HorizontalAlignment="Left" Margin="135,421,0,0" Name="dataGrid2" VerticalAlignment="Top" Width="1049" Background="#F3333333" RowBackground="#F3333335" Foreground="WhiteSmoke" />
<Button Content="Run Query" Height="23" HorizontalAlignment="Right" Margin="0,509,1084,0" Name="button2" VerticalAlignment="Top" Width="93" Click="button2_Click" />
<ComboBox Height="23" HorizontalAlignment="Right" Margin="0,453,1068,0" Name="comboBox2" VerticalAlignment="Top" Width="120" SelectionChanged="comboBox2_SelectionChanged" />
<sdk:DataPager Height="26" HorizontalAlignment="Left" Margin="135,687,0,0" Name="dataPager2" PageSize="10" VerticalAlignment="Top" Width="1047" Background="#F3333333" Foreground="WhiteSmoke" />
<RadioButton Content="By PcSn" Height="33" HorizontalAlignment="Right" Margin="0,389,1075,0" Name="radioButton1" VerticalAlignment="Top" Foreground="WhiteSmoke" FontSize="18" Width="109" />
<RadioButton Content="By T-Box" Height="33" HorizontalAlignment="Left" Margin="8,421,0,0" Name="radioButton2" VerticalAlignment="Top" Foreground="WhiteSmoke" FontSize="18" Width="131" />
<TextBox Background="#FF0E0E0E" Height="34" HorizontalAlignment="Left" Margin="668,387,0,0" Name="textBox1" VerticalAlignment="Top" Foreground="WhiteSmoke" FontSize="12" Width="428" BorderBrush="Black" />
<ListBox HorizontalAlignment="Left" Margin="12,86,0,0" Name="listBox1" Width="120" Background="#F3333333" Foreground="WhiteSmoke" Height="263" VerticalAlignment="Top" />
</Grid>
</navigation:Page>
|
|
|
|

|
Make sure you have all the third party components installed on the machine.
|
|
|
|

|
I am using WPF, C#, Linq to Sql -- I have a stored procedure and I am trying to bind the results to a treeview two levels deep. Below is some of the code I thought might help understand better, I am not sure if I needed to post this much code, but I can remove the uneeded code. I am having trouble figuring out the bindings with the data-templates. Any suggestions or comments would be appreciated.
Here is part of the view model I am using
public sealed class AViewModel : ViewModel
{
public sealed class ItemsToGet
{
public Guid? Id {get; set; }
public int? TNumber { get; set;}
public string Title { get; set; }
public string Description { get; set; }
public string FullName { get; set;}
}
private Guid mText = Guid.Empty;
private ObservableCollection<ItemsToGet> mHistory = new ObservableCollection<ItemsToGet>();
public ObservableCollection<ItemsToGet> History
{
get
{
return mHistory;
}
}
public Guid SearchText
{
get
{
return mText ;
}
set
{
mText = value;
OnPropertyChanged("SearchText");
}
}
var itemlist = from s in context.GetHistory(mText)
select new ItemsToGet()
{
Id = s.Id,
TNumber = s.TNumber,
Title = s.Title,
Description = s.Description,
FullName = s.FullName
};
List<ItemsToGet> Results = itemlist.ToList();
mHistory.Clear();
Results.ForEach(b => mHistory.Add(b));
Here is the View Code Behind
public partial class AView : UserControl
{
public AView()
{
InitializeComponent();
AViewModel vm = this.DataContext as AViewModel;
}
}
Xaml -- I want to top level to display the Title, and the child(second level to be the TNumber)
<TreeView ItemsSource="{Binding History}">
-->
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding History}">
<TextBlock Foreground="Red" Text="{Binding Title}" />
-->
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding History}">
<TextBlock Text="{Binding TNumber}" />
-->
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</UserControl>
Here is a snapshot of what the results look like, there are more rows than this, but this is the format.
Trying to display it like below. Thanks for any comments or suggestions.
Design 1
--Tnumber 1
--TNumber 2
Design 2
--TNumber 1
--TNumber 2
--TNumber 3
Design 3
--TNumber 1
ETC
ETC
|
|
|
|
|

|
You need 2 clases a Design class and a Tnumber class, your Design class must have an observable collection of Tnumbers.
Populate the Design class with the unique of the design field. In the tnumber collection add the records for each design type.
Binid your treeview to the design collection, bind the hierarchy template to the tnumber collection.
Never underestimate the power of human stupidity
RAH
|
|
|
|

|
Trying to use VisualTreeHelper.HitTest on a TreeView. I have two arbitrary items. TreeViewItem1 and TreeViewItem2. These items may appear anywhere on the tree and have any sort of relationship (different parents, etc.). I've gotten the top left point of the two items. pt1 and pt2. I want to find the visible TreeViewItems in between. So I did: VisualTreeHelper.HitTest(ParentTreeView, new HitTestFilterCallback(A), new HitTestResultCallback(B), new GeometryHitTestParameters(new RectangleGeometry(new Rect(0, pt1.Y, ParentTreeView.ActualWidth, (pt2.Y + 1) - pt1.Y)))); HitTestFilterBehavior A(DependencyObject potentialHitTestTarget) { if (potentialHitTestTarget is TreeViewItemEx) { if (((UIElement)potentialHitTestTarget).IsVisible) System.Diagnostics.Debug.WriteLine(potentialHitTestTarget); } return HitTestFilterBehavior.Continue; } HitTestResultBehavior B(HitTestResult result) { return HitTestResultBehavior.Continue; } This code is working for the most part, except it's also returning parent items that it shouldn't. If my tree looks like: 1 _2 __3 and the two items in question are 2 & 3, the hit-test also returns 1. A more ugly example is: Root _NodeWithChildren1 _NodeWithChildren2 _NodeWithChildren3 __1 __2 __3 the tree looks exactly like that on the screen. The items in question are _NodeWithChildren3 and __1. The hit-test returns Root and _NodeWithChildren1 and _NodeWithChildren2 as well. Any ideas? I have confirmed that I am getting the correct item1 & item2 that I think I am getting and I have confirmed that the points I am getting are correct as well.
|
|
|
|

|
Cant you cast the object or check the object using TypeOf, and then check were it is in the treèviewcontrol?
|
|
|
|

|
I posted on this a while back, and I'v tried some things but still cannot get this to work.
The Problem
When I have multiple tabs open, and I click the Close X on a NON-ACTIVE tab, the active tab is closed.
The XAML
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type TabItem}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate >
<Grid HorizontalAlignment="Stretch" Height="22">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="1"
Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem} }, Path=Header}"
VerticalAlignment="Bottom" Margin="4,0,8,0"/>
<Button Grid.Row="1"
Grid.Column="1"
Height="16"
Width="16"
BorderBrush="{x:Null}"
Background="{x:Null}"
Foreground="#FF224A71"
VerticalAlignment="Center"
Padding="3,0"
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=DataContext.CloseTabCommand}">
<TextBlock Text="x"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="0,0,0,2"/>
<Button.ToolTip>
<controls:ToolTipEx Style="{StaticResource TooltipStyle}"
HeaderText="Close"
Icon="/FMG.UI.WPF;component/Media/Images/closetab_24.png"
ContentAreaText="Closes this tab"/>
</Button.ToolTip>
<Button.OpacityMask>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#4BFFFFFF" Offset="1"/>
</LinearGradientBrush>
</Button.OpacityMask>
</Button>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</UserControl.Resources>
The problem as I see it is that the view model doesn't know which tab fired the command.
Can someone help me figure this out?
Thanks
If it's not broken, fix it until it is
|
|
|
|

|
I too was running into this same problem with this EXACT command. However this article on c# corner and this article on CP helped me to fix it.
Hope it works!
|
|
|
|

|
I am using this in the code behind for a xaml page and it works fine for retrieving the data for a listbox:
_______________________________________________________________
SLConnDomainContext dbContext = new SLConnDomainContext();
private LoadOperation<Employee> loadOp;
ObservableCollection<Employee> data = new ObservableCollection<Employee>();
public Filters()
{
InitializeComponent();
loadOp = this.dbContext.Load(this.dbContext.GetEmployeesQuery());
loadOp.Completed += new EventHandler(loadOp_Completed);
}
void loadOp_Completed(object sender, EventArgs e)
{
foreach (Employee emp in loadOp.Entities)
{
data.Add(emp);
}
dataForm.ItemsSource = data;
}
I would like to move to a MVVM approach and have created a viewmodel to retrieve the data and pass it into a view by creating an instance of my viewmodel and setting the datacontext property of my listbox. The viewmodel works fine when I am just creating some mock data and populating a list. However, due to the asynchronous nature of using a loadoperation with silverlight, the above code doesn't work with the MVVM approach for me. The data is retrieved but it appears that it is after my view has already loaded so it never appears. Below is my code:
Viewmodel:
______________________________________________________________
{
public partial class EmployeeService
{
private SLConnDomainContext Context = new SLConnDomainContext();
private LoadOperation<Employee> loadOp;
public ObservableCollection<Employee> employees = new ObservableCollection<Employee>();
public EmployeeService()
{
loadOp = Context.Load(Context.GetEmployeesQuery(), LoadBehavior.MergeIntoCurrent, employeeCallBack, null);
}
void employeeCallBack(LoadOperation<Employee> op)
{
foreach (Employee emp in loadOp.Entities)
{
employees.Add(emp);
}
_myEmployees = employees;
MessageBox.Show("I have " + employees.Count + " employees");
}
public IEnumerable<Employee> GetEmployees()
{
return employees;
}
public event PropertyChangedEventHandler PropertyChanged;
private ObservableCollection<Employee> _myEmployees;
public ObservableCollection<Employee> myEmployees
{
get { return _myEmployees; }
set
{
myEmployees = value;
OnPropertyChanged("myEmployees");
}
}
private int _EmployeeID;
public int EmployeeID
{
get { return _EmployeeID; }
set
{
_EmployeeID = value;
OnPropertyChanged("EmployeeID");
}
}
private int _VacationHours;
public int VacationHours
{
get { return _VacationHours; }
set
{
_VacationHours = value;
OnPropertyChanged("VacationHours");
}
}
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
This is set in the constructor for the view's code behind:
______________________________________________________________
public LayoutTest()
{
InitializeComponent();
EmployeeService myservice = new EmployeeService();
EmployeeList.DataContext = myservice;
}
I have the databinding set correclty as it works if I use something like this in place of the above GetEmployees():
______________________________________________________________
public IEnumerable<Employee> GetEmployees()
{
List<Employee> employees = new List<Employee>();
EmployeeService test = new EmployeeService();
foreach (Employee emp in test.GetEmployees())
{
employees.Add(emp);
}
Employee employee = new Employee();
employee.EmployeeID = 1111;
employee.VacationHours = 100;
employees.Add(employee);
employee = new Employee();
employee.EmployeeID = 1112;
employee.VacationHours = 62;
employees.Add(employee);
employee = new Employee();
employee.EmployeeID = 1113;
employee.VacationHours = 132;
employees.Add(employee);
return employees;
}
I am sure this is due to the asynchronous call but I don't know how to fix it. Thanks for any help.
|
|
|
|

|
Why do you have _employees and _myEmployees? The main issue is that _myEmployees = employees doesn't trigger a change notification, so you'd have to call OnPropertyChanged("myEmployees") after the assignment. That is the correct method, but then employees should be a local object, not a class member.
|
|
|
|

|
Wow! Thank you....That was it.
|
|
|
|

|
I could not find no example on how to write a wpf control that wraps c++ win32 window. If some one could provide me with a link to a newbie-like tutorial/documentation (sample code would be good too) on how to create c# libraries that wrap c++ code I would be very thankful.
Thanks in advance.
|
|
|
|
|

|
Hi!
Thx for the link. I found that one my self and I tried to modify the sample code to my needs but i failed.
I'll try to explain more what I'm trying to do.
So I have 3rd party OpenGL application written in C++ that is capable to show its output on another process window by passing a HWND pointer of that window (re-parenting).
If I create basic C++ Win32 aplication and pass its window HWND to that 3rd application I see output of that application in my application window.
Since I don't know C++ programming that well and I'm a little better at C#, I would like to create a WPF control that wraps C++ window in a dll that I can use in my WPF project.
Now the problem is that I can't figure out how to override WM_PAINT function so that WPF would be able to render that control correctly.
Because now I get that control instantiated and I get the HWND of that control (which is different of the WPF window hosting it) but when I pass it to that 3rd party application nothing happens.
My guess is that WM_PAINT is being called correctly but WPF window is not rendering that control because it knows nothing of WM_PAINT ?!
Now, the MSDN resource is a bit difficult for me to figure out how to solve my problem. Mostly because I need some easy reading on how to write managed c++/clr code.
Any suggestion on some websites or books that explain this subject (on elementary school level ) ?
Thx again!
|
|
|
|

|
You can get the native HWND of a WPF control / window. Wait for the SourceInitialized event and then:
HwndSource hWndSource = (HwndSource)PresentationSource.FromVisual(window);
the HWND is in hWndSource.Handle. WPF hides WM_PAINT from you so it can do all the double buffering, effects, transformations, etc.
|
|
|
|

|
So I have PInvoked BeginPaint() and EndPaint() funcrions also.
And I'm able to draw inside my win32 window from there.
But my 3rd party application still can't and I don't know what else do I need to override to make it work.
At this point there is no difference between win32 window hosted in WPF application and win32 window created by c++ win32 application or is there ?!
Maybe type of class inside CreateWindowEx function ("static") should be something different, or some of window parameters should be changed.
My guess is that WPF is preventing win32 window from communicating with 3rd party process. Response from 3rd party app is: "visual not possible"
Here is link to my project if anyone interested to look what I did so far.
http://sdrv.ms/10VSWbD[^]
Don't know if there is a way to simulate my situation by trying to redirect (reparent) some other application (that uses win32) window output to my app. I'm not in position to share that 3rd party application that I'm using.
|
|
|
|

|
Did you try passing the 3rd party app the HWND from:
HwndSource hWndSource = (HwndSource)PresentationSource.FromVisual(window);
The HWND in hWndSource.Handle and bypassing your C++ app entirely?
I don't think "visual not possible" is a WPF error, sounds like its coming from the 3rd party vendor. Have you tried contacting them if they support redirection?
|
|
|
|

|
Yes I tried your suggestion and still no success.
The 3rd party vendor don't consider this to be a valid customer API request as this is something they use internally (they have couple of apps that can do this and they have some interop wpf dll's for this but it is not exposed for others)
|
|
|
|

|
Hmmm... maybe its not possible then. If you can do it in C++, then you should be able to take that C++ window and host it on a WPF form. My only other suggestion would be to maybe package it as an ActiveX control and then host that on the WPF form natively. Not sure if it will work though...
|
|
|
|
 |