|
Never used the WPF toolkit, but thanks for the pointer. The DataGrid appears to have a number of features that will make it a much more attractive solution. Thanks for the comment. That's just what I needed.
|
|
|
|
|
Hello
I'm scaling some Polyline s, and for some I want the thickness of the line to follow the scale, works fine by default, but for some I want to keep a fixed pixel width regardless of scale.
Is that possible in some simple way or do I have to calculate the StrokeThickness myself?
thanks in advance
Niklas
|
|
|
|
|
Niklas Lindquist wrote: I'm scaling some Polylines
How are you currently doing this?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Oh, sorry, I'm setting a TransformGroup containing a ScaleTransform and a TranslateTransform , on the Polyline s RenderTransform property.
I managed to recalculate the width, but it adds a lot of overhead in adding a number of event handlers. So I'm still interested in a simpler way to do this.
/Niklas
|
|
|
|
|
Niklas Lindquist wrote: I'm still interested in a simpler way to do this
I don't know of a simpler way. My guess is that you'd need to
scale/translate the polyline points separately and create a new PolyLine
from those points if you want to prevent the strokethickness from getting
transformed.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
That's just as bad as recalculating the width I'd guess (if not worse, performance wise).
Thanks for taking the time.
/Niklas
|
|
|
|
|
hello everybody Iwant to create video chat application in wpf and that should be peer to peer. I developed an application by looking article at codeproject wpf/wcf peer to peer chat application . But thats simply broadcasting my video to other peers and when the other peer starts sharing his cam then the both stream mixes up and I get output on my screen in which the streams of both the users mixes up and I we see pictures of both the users alternatively. and moreover it has performanve issuses also. video quality is perfect but speed is very very slow. So plz guide me how to do this???????????
|
|
|
|
|
I suspect you need to fix the code you're using to not send both streams across the same connection, and that you need a faster internet connection to get good video.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Thanks for replying but can u suggest me someway. how to do this.In my peer to peer application there is only one function that I have declared in the interface and is automatically called for all the nodes in the mesh. and that fnction is accepting "stream " of the person who started sharing his video to others,and this fnctio is called for each node, If now some other user starts his video sharing then it will again call the same function that was already running for this user and the rest of users and at thuis stage both the streams get mixed and I havnt found a way to separate these streams and call the function that is accepting stream.
|
|
|
|
|
HI,
This is from Chandrakanth.
Working on WPF Project.
Actually i have one CheckButton called as CheckALL. I have one DataGrid.
DataGrid Consist of some rows.
I want to Click on that CheckAll Button than all the rows in DataGrid should check.
How can i write that in WPF. Can any one tell me about that.
Thanks and Regards
Chandrakanth
Responses
|
|
|
|
|
You would have a boolean property on the data, let's call it Selected. Then you bind your checkbox to the property, and your code simply updates the data - leaving the binding engine to ensure that the checkbox is updated as a result. Don't try to do something like this in the UI, use the data to control it.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
HI,
Pete O'Hanlon,
Thaks for the early reply.
Once Again from Chandrakanth.
Actually i have bind the data to the DataGrid Control.
I have 4 rows in that dataGrid with every row containing CheckBox in
the first Column.
My Problem How to Check all the rows in the DataGrid, when i
click on CHECKALL button.Actully i was tried with some code to
check all Rows in DataGrid. But Unable to that. i need help on that.
If you have any code on that Please reply to me.
Thanks and Regards
Chandrakanth
|
|
|
|
|
I've already told you how to do it. Don't try to programatically check items in the grid, use the model to do this. Suppose you have a model that looks like this:
public class MyItem : INotifyPropertyChanged
{
private bool _selected;
private string _name;
private event PropertyChangedEventHandler _changed;
public event PropertyChangedEventHandler Changed
{
add { _changed += value; }
remove { _changed -= value; }
}
public bool Selected
{
get { return _selected; }
set
{
if (_selected != value)
{
_selected = value;
OnChanged("Selected");
}
}
}
}
public class MyViewModel
{
private ObservableCollection<MyItem> _items = new ObservableCollection<MyItem>();
public void HandleCheckAll
{
foreach (MyItem item in _items)
{
item.Selected = true;
}
}
public ObservableCollection<MyItem> Items
{
get { return _items; }
}
}
All you need then is a command that calls HandleCheckAll and the grid binding to the MyViewModel.Items . The checkbox is bound (two-way) to Selected , and job's done.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Apologies in advance, I suspect there may be an obvious answer to this, but I have searched these forums and google and not really been able to determine the solution.
This is for a WPF application, but I think it is a more general programming question.
We have an ObservableCollection(of T), where we need do do some validation of the member object, T. One of the rules is that a property of T (say name) cannot already exist in the collection.
Our validation class is instantiated from the xaml, so I don't know of any way to pass in the reference to the ObservableCollection. However, this is needed to be able to step through the collection, to see if name has already been used, and report an error (if needed).
One solution I can see is that the class T could have a property which is an ObservableCollection of T, and then you pass the parent collection into the member object. I think this will solve the issues, but something says to me this would be bad practise... Can anyone clarify whether this will cause errors or should be avoided? Can anyone suggest an alternative?
More specifically, say we define Person
Public Class Person
Public Sub New(ByVal Name As String, ByVal People As ObservableCollection(Of Person))
...
End Sub
Public Property Name() As String
...
End Property
Public Property People() As ObservableCollection(Of Person)
...
End Property
End Class
Then elsewhere make a collection of Person
Dim MemberList As New ObservableCollection(Of Person)
MemberList.Add(New Person("John", MemberList))
MemberList.Add(New Person("Fred", MemberList))
MemberList.Add(New Person("Jane", MemberList))
MemberList.Add(New Person("Andrew", MemberList))
Then we can bind say a WPF DataGrid to MemberList, and use validation to check our rule, to check that the Person name has not already been used in the ObservableCollection(of Person) - ie MemberList. The approach here will work, but I am concerned that there might be underlying problems - some circular reference or something (or else just not good practise).
Thanks for any suggestions.
Tim
|
|
|
|
|
Tim
What you are after is an ObservableDictionary. The good Dr WPF has a sample implementation of one here[^].
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete,
Thank you for your reply. I have read the article you refer to ("The Observable Dictionary Sample" - correct?), however I am not clear on how this might solve the problem.
I need to explain a bit more about the scenario. We have a WPF DataGrid bound to our ObservableCollection - this works really well. I am now trying to handle validation as a user makes changes. Where the valiadtion can be based solely on the content of the member object (ie the data in the row, e.g. ensure an age is between 5 and 50) - no problem, use the ValidationRule approach as is well documented. What I am having trouble with is the scenario where a value must be checked against all others in the ObservableCollection - I don't know of any way to make the ValidationRule class know about the parent collection.
So I think this problem will exist, whether we are using ObservableCollection or ObservableDictionary. Please correct me if I have misunderstood your post.
Maybe I am missing something, on how we can pass in the parent collection, to the ValidationRule instance (ie NameRule) that is doing the validation.
Our xaml is
<toolkit:DataGridTextColumn Header="Name" Width="100" >
<toolkit:DataGridTextColumn.Binding >
<Binding Path="Name" >
<Binding.ValidationRules>
<local:NameRule ValidationStep="UpdatedValue"/>
</Binding.ValidationRules>
</Binding>
</toolkit:DataGridTextColumn.Binding>
</toolkit:DataGridTextColumn>
There could be several ways to solve this, outside of the DataGrid, but I am trying to find the best method which utilises the WPF way of doing validation.
BTW, I have reviewed the excellent article "WPF DataGrid Practical Examples" [^], and this addresses data validation. However the example provided is based on a DataTable as itemssource (in which case you can refer back to the DataTable), and it seems there should also be a way to use ObservableCollection as the itemssource.
Any further suggestions would be appreciated.
Tim
|
|
|
|
|
The reason I suggested an ObservableDictionary is that it, by default, solves the problem where you can't have an entry with the same key name. One thing I would say - move your validation out of the binding into a ViewModel, it's a lot easier to test and you can make your rules a lot more flexible, especially as you would have full programattic access to your ObservableCollection.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete,
Thanks for the suggestion of using a ViewModel. I am a big fan of using ViewModel and have made extensive use of this pattern in our project (where it fits). I found your article "Action based ViewModel and Model validation." and Josh Smith's article "Using a ViewModel to Provide Meaningful Validation Error Messages" on this approach (I assume that is what you meant), and have now modified the project accordingly.
So the original class was ATUser and I defined a new UserViewModel class which wraps ATUser. I have been able to achieve the validation (and it works nicely), however I am still not sure I am following good programming practise (really my original question), because I found it essential to pass a reference to the ObservableCollection (container collection), into each UserViewModel member, so the member could find out if the user name had already been used.
So a snippet of UserViewModel is
Public Class UserViewModel
Implements INotifyPropertyChanged
Implements IDataErrorInfo
Private _user As ATUser
Private _containerCollection As AUSObservableCollection(Of UserViewModel)
Public Sub New(ByRef User As ATUser, _
ByRef ContainerCollection As AUSObservableCollection(Of UserViewModel))
_user = User
_containerCollection = ContainerCollection
_username = _user.Username
End Sub
'lines removed
Default Public ReadOnly Property Item(ByVal propertyName As String) As String Implements IDataErrorInfo.Item
Get
Select Case propertyName
Case "Username"
'logic to determine if Username is valid, which involves searching through _containerCollection
End Select
End Get
End Property
End Class
So I believe I have achieved the goals of using the ViewModel, which include improved control over Data Validation. However I'm not sure I addressed my original concern - which is holding a reference to the containing collection within the member object itself.... Could you comment on whether I have missed the point / whether there is a more acceptable way to solve this / whether the reference to the containing collection is OK? Just to restate, in order for a UserViewModel to validate the Username property, it needs to access the containing collection, in order to see if the name has already been used.
From the Data Validation point of view, I could have achieved the same by implementing IDataErrorInfo on the ATUser class, and simply adding a Property to hold the reference to the containing collection (which would take much less time and be easier to maintain, but would loose the other benefits of ViewModel). I have about 9 similar classes in this project, so I would like to get this right before moving on.
Thanks again for your help, and apologies if I am asking a basic question.
Tim
|
|
|
|
|
Another alternative I have discovered is to use a shared member property of a Helper object to hold the collection that needs to be searched.
I can define this as follows:
Public Class ATBusinessInfoHelper
Private Shared _userContainer As AUSObservableCollection(Of ATUser)
Public Shared Property UserContainer() As AUSObservableCollection(Of ATUser)
Get
If _userContainer Is Nothing Then
Throw New AUSException("UserContainer has not been defined")
Else
Return _userContainer
End If
End Get
Set(ByVal value As AUSObservableCollection(Of ATUser))
_userContainer = value
End Set
End Property
End Class
Then in the IDataErrorInfo validation logic, I can step through ATBusinessInfoHelper.UserContainer to see if there is a conflict with an existing name. Would this be a valid approach to take?
Thanks for any advice,
Tim
|
|
|
|
|
I am new to wpf.
I have created a reflective textblock usercontrol .
<UserControl
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" x:Class="LogoCreator.ReflectiveTextBlock"
Height="50" Width="189" mc:Ignorable="d">
<UserControl.Resources>
<VisualBrush x:Key="ReflectionBrush" Visual="{Binding ElementName=textBlock}"/>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock x:Name="textBlock" Grid.Row="0" Margin="0" FontSize="18.667" Text="Sample1" TextWrapping="Wrap" HorizontalAlignment="Left" Background="White"/>
<Rectangle x:Name="Reflection" Grid.Row="1" Margin="0,1,0,-32" RenderTransformOrigin="0.5,0.5" Fill="{DynamicResource ReflectionBrush}">
<Rectangle.OpacityMask>
<LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
<GradientStop Color="#7EFFFFFF" Offset="0"/>
<GradientStop Offset="0.5"/>
</LinearGradientBrush>
</Rectangle.OpacityMask>
<Rectangle.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="-1"/>
</TransformGroup>
</Rectangle.LayoutTransform>
</Rectangle>
</Grid>
</UserControl>
I have the rectangles fill property set to the textblocks visual brush.
The problem is when this control is add to the main window canvas, it shows only the text, the reflection is not shown.
Is it because the visualbrush resource is within the usercontrol ?
How do i solve it ?
|
|
|
|
|
Ive solved it by replacing the rectangle with border. And setting the borders background to visualbrush binded to textblock, without using resources.
I think the problem was that the visualbrush resource was within the usercontrol.
Thank you.
|
|
|
|
|
I am seeking help from the pros of WPF and 3D graphics to recommend books on the title mentioned that helped them. I did my search on Google but most examples assume you already know what the deal is (first time to try 3D in WPF).
Basically I have a 3D Model (plain) and a (Colored one or with texture). How to export it to something that WPF understands plus I want to use the mouse as the interacting device finally some properties the user can select and when a button is clicked the model change accordingly.
Is it also possible to convert the current camera view to an image and use it in Crystal reports?
Can I render many models at the same time (without showing it) and export the result to image and use it as a data source in crystal reports?
Can the user select the view of the camera view (via check box) before rendering the model (hidden) then use it in crystal report?
Suppose I have a cube, can I select a side from the cube and right click on it to get a menu similar to the menu when you right click on the desktop?
I am not asking for an implementation, only good references to help with the problem.
Thank you
|
|
|
|
|
I think Adam Nathan's WPF Unleashed[^] is one of the best on the market, with a good section on 3D.
[edit]Changed category to general[/edit].
|
|
|
|
|
Depending on what program your using for your 3d model, some programs will actually export the model as an xaml object. Makes life great .
|
|
|
|
|
All i want is to use MVVM pattern
I should use a form
example:
customer form which contains customer name and customer id
probably the application should use command when the save button is clicked
and add this data to the table in the database.
Can somebody send me how to do this.
I know how to do this with out the MVVM pattern
|
|
|
|