Click here to Skip to main content
       

Silverlight / WPF

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
QuestionHOW TO ANSWER A QUESTIONadminChris Maunder16-Jul-09 3:09 
Apologies for the shouting but this is important.
 
When answering a question please:
  1. Read the question carefully
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
  3. If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
  4. 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

QuestionHow to get an answer to your questionadminChris Maunder16-Jul-09 3:05 
For those new to message boards please try to follow a few simple rules when posting your question.
  1. Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
     
  2. 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.
     
  3. Keep the subject line brief, but descriptive. eg "File Serialization problem"
     
  4. Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
     
  5. 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.
     
  6. 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.
     
  7. 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.
     
  8. Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
     
  9. 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.
     
  10. Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
     
  11. If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
     
  12. No advertising or soliciting.
     
  13. 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

QuestionError in WpfmemberNick_Frenk16-Jun-13 21:57 
hello guys, I need help, I'll explain the problem ...
I am making a wpf project that pressing a buttom let me see the video of the IP camera, only to see that the string directly to the video does not work, so I use the string of the image that is updated every time, to do this use the thread, and to avoid exceptions, use the delegates, only that at some point I will generate this error:
An unhandled exception of type 'System.StackOverflowException' in WindowsBase.dll

 
The point at which I generate error is as follows:
Del Ert = new Del(setImage);
  images.Dispatcher.Invoke (ert, new object [] {images, url});
 

the type
Del
is my delegate:
public delegate void Del (Image images, string url);

I hope you can help me, if you need some additional information I can post it
AnswerRe: Error in WpfprotectorPete O'Hanlon16-Jun-13 23:20 
There's not really enough to go on here. You've only shown a couple of partial lines here. Saying that, a StackOverflow indicates that you are causing a recursive call here. Open the Stack Trace window and let your application run until it fails - when the exception is generated, take a look at what's in the stack trace.
I was brought up to respect my elders. I don't respect many people nowadays.

CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

GeneralRe: Error in WpfmemberNick_Frenk17-Jun-13 0:03 
hi, I put a break-point and I noticed that IF is the cycle that makes me run any code inifinite times, but only the first line in the IF.

public void setImage(Image images,string url)
        {
            
            if (images.Dispatcher.CheckAccess())
            {
                MessageBox.Show("ciao");
                Del ert = new Del(setImage);
                
                images.Dispatcher.Invoke(ert, new object[] { images, url });
                BitmapImage img = new BitmapImage();
                img.BeginInit();
                img.UriSource = new Uri(url);
                img.EndInit(); // Getting exception here 
                images.Source = img;
            }
            else
            {
                images.Dispatcher.BeginInvoke(new Del(setImage), DispatcherPriority.Normal,
                                                     new object[] { images, url });
                //images.Dispatcher.Invoke(new Action(Esc));
            }
        }
 
 
        public void StreamImg()
        {
            while (true)
            {
                var date = DateTime.Today.Hour;
                setImage(image1, @"http://ipaddress/jpg/image.jpg" + "?" + date);
                Thread.Sleep(1000);
             }
        }
        

GeneralRe: Error in WpfmvpRichard MacCutchan17-Jun-13 0:25 
Please don't post the same question in multiple forums. You already received help on this issue in the C# forum.
Use the best guess

GeneralRe: Error in WpfmemberNick_Frenk17-Jun-13 0:38 
Yes, i'm sorry.. how do I delete this question? Smile | :)
GeneralRe: Error in WpfmvpRichard MacCutchan17-Jun-13 0:57 
You can't; just leave it as it is.
Use the best guess

QuestionMove datatable/set between multiple wpf windowsmemberMember 989260614-Jun-13 4:57 
Hi Guys,
 
I am a bit new to wpf and was wondering if you guys could point me in the right direction. I am creating a database program. What I want to do is create a window with a datagrid to display my data and create another window where I can plot the data and create graphs. I want to go with two windows or more because most people here at work use dual monitor setups and it would be helpful not to have something like Visual studio's dockable layout. Eventually I will also want to select samples in the mainwindow datagrid and have the highlighted in the graphs and think that I would need to use the same dataset/table to accomplish that, is that correct?
 
My question is this, how do I access the dataset/table in the mainwindow from window2? The dataset/table is filled from excel/sqlCE.
 
All I could find so far was to create an inheritance but I couldn't find any mention of moving entire dataset/tables between windows, and I think filling a new dataset with the same data may eat up lots of resouces down the road.
 
Any help would be appreciated. Perhaps someone has come accross a similar problem in the past and has some insights.
 
Many thanks in advance.
AnswerRe: Move datatable/set between multiple wpf windowsprofessionalMycroft Holmes8hrs 53mins ago 
Presumably you are binding your grid to a collection which resides in a ViewModel (if it is in the code behind then research MVVM). I would bind both windows to the same ViewModel as you want the selection event in one to affect the 2nd window (View).
 
A purist would probably set up a messaging system between 2 distinct ViewModels.
Never underestimate the power of human stupidity
RAH

QuestionReorder the columns in a data gridmembercolumbos1492713-Jun-13 4:26 
Hello,
I defined the next data grid:
<toolkit:DataGrid
      ItemsSource="{Binding LogList}">
</toolkit:DataGrid>
 
And when in my view model file i update the LogList the data in the data grid is also uopdated everything is fine.
But there is one problem the automaticly generated columns are not in the order that i would like them to be.
 
How can i fix it?
 
Thanks
AnswerRe: Reorder the columns in a data gridprofessionalMycroft Holmes9hrs 1 min ago 
columbos14927 wrote:
the automaticly generated columns are not in the order that i would like them to be

The turn off the auto generation and create the columns as you want them.
Never underestimate the power of human stupidity
RAH

QuestionSilverlight Chartsmemberswatibahl0412-Jun-13 19:56 
How to create multi-category charts in silverlight.
I have 3 columns in my data Financial year , Quarter, amount paid.
based on one single id i fetch the records and then plot data for these 3 columns.
I want financial year and quarter on category axis.
AnswerRe: Silverlight ChartsmvpAbhinav S12-Jun-13 20:49 
Use charting in the Silverlight toolkit[^].

GeneralRe: Silverlight Chartsmemberswatibahl0412-Jun-13 20:55 
I have created a chart that displays multiple series using silverlight toolkit only, but i want a multi-category chart in silverlight.
AnswerRe: Silverlight ChartsmvpAbhinav S12-Jun-13 21:03 
If you want to switch between different charts you can always do so.
 
Otherwise, you can try and template / customize the chart that is closest to your requirement.
GeneralRe: Silverlight Charts [modified]memberswatibahl0412-Jun-13 21:38 
I want this for column series is it possible..
 
Can u please help me in doing this

modified 13-Jun-13 4:35am.

GeneralRe: Silverlight ChartsmvpAbhinav S13-Jun-13 1:10 
Its possible. Styling the Chart Control in the Silverlight 4 Toolkit[^] might help.

GeneralRe: Silverlight Chartsmemberswatibahl0413-Jun-13 1:22 
okk thank you so much
Questionchange color of Datagrid textmemberpicasso210-Jun-13 18:12 
Hello members,
I have tables (DBTable) in SQL 2008 that contains two columns that look like this:
Col1 Col2
0 1
0 1
1 1
1 1
0 1
I created a Silverlight application (BI -RIA and domain services) that populates the datagrid as follows
MyCarsDomainContext context = new MyCarsDomainContext();
dataGrid1.ItemsSource = context.DBTables;
context.Load(context.GetDBTablesCompareQuery());
 

I would like to change the row background color (just the text color will work fine too) based on the value of Col1. If 0 then row is red, if 1 then row is blue
 
Any help is greatly appreciated
AnswerRe: change color of Datagrid textmemberAbhijeetB12-Jun-13 1:18 
Use DataGridTemplateColumn and use Textblock/Textbox controls. Use converter to set forecolor of textbox as per the binded value to Text property
-Abhijeet B

AnswerRe: change color of Datagrid textmvpAbhinav S12-Jun-13 20:51 
You can do this via the converter approach.
Call the converter during binding and set data fore color to the respective color in the converter.
 
A simple example here[^].

QuestionMediastreamsourcememberbrodcasting10-Jun-13 2:45 
audio samples to wmv file using mediastreamsource
AnswerRe: MediastreamsourcemvpRichard MacCutchan10-Jun-13 3:29 
If you copy and paste those exact words into Google you will probably get some useful information.
Use the best guess

Questionaudio samples to wmv file using mediastreamsourcememberbrodcasting7-Jun-13 21:44 
i want to get both samples audio and video using mediastreamsource .
QuestionURL Issuememberidreesbadshah5-Jun-13 20:01 
Hi,
I have a silver light application. When I run it then its URL is like http://localhost/Myfirstapplication.aspx.
I have created another silver light application. Mostly code is copied from first application. But when I run it then its URL is like http://localhost/mysecondapplication.aspx#loginpage.xaml.
Actually I donot want to show .xaml path/name. Can any body tell me what setting should I made to hide .XAML or am I missing somthing ???
QuestionSilverlight business applicationmemberpicasso23-Jun-13 19:19 
How can I run a store procedure (SQL 2008) from domain services?
 
default method is to simple
 
public IQueryable GetCars()
{
return this.ObjectContext.Cars;
}
 
It does not have to be a SP, I just thought it may be cleaner, basically what I need to run is something like this:
 
Select col1 from DBTables where ltrim(rtrim(col1)) not in (select ltrim(rtrim(col2)) from DBTables where col2 is not null)
order by 1
Select col2 from DBTables where ltrim(rtrim(col2)) not in (select ltrim(rtrim(col1)) from DBTables where col1 is not null)
order by 1
 
any help is greatly appreciated
AnswerRe: Silverlight business applicationmvpAbhinav S10-Jun-13 20:25 
This link could possible help you - Working with Entity Data Model and Executing Stored Procedures[^].

QuestionWPF Combo box not display bound valuememberDisIsHoody2-Jun-13 10:10 
I'm relatively new to WPF but I've gotten a decent handle on how data binding works except with combo boxes. I have a window in my application that when it loads it shows a list box with all the currently entered users' information. When a item is selected all the information is loaded into text boxes/combo boxes for editing. I got the data binding to work with the text boxes, but I can't get the combo box to bind to the gender property.
 
I have a class that represents a person. This is a stripped down version with just some of the properties, including the gender property that the combo box needs to bind to:
Public Class Person
    Implements IPerson, INotifyPropertyChanged
 
#Region "Events"
    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
#End Region
 
#Region "Variables"
    Private _guid As Guid
    Private _firstName As String
    Private _lastName As String
    Private _MiddleName As String
    Private _sex As String
    Private _created As DateTime
    Private _modified As DateTime
#End Region
 
#Region "Properties"
    Public ReadOnly Property GUID As Guid Implements IPerson.GUID
        Get
            Return _guid
        End Get
    End Property
 
    Public ReadOnly Property Created As Date Implements IPerson.Created
        Get
            Return _created
        End Get
    End Property
 
    Public ReadOnly Property Modified As Date Implements IPerson.Modified
        Get
            Return _modified
        End Get
    End Property
 
    Public Property FirstName As String Implements IPerson.FirstName
        Get
            Return _firstName
        End Get
        Set(value As String)
            _firstName = value
            OnPropertyChanged(New PropertyChangedEventArgs("FirstName"))
        End Set
    End Property
 
    Public Property LastName As String Implements IPerson.LastName
        Get
            Return _lastName
        End Get
        Set(value As String)
            _lastName = value
            OnPropertyChanged(New PropertyChangedEventArgs("LastName"))
        End Set
    End Property
 
    Public Property MiddleName As String Implements IPerson.MiddleName
        Get
            Return _MiddleName
        End Get
        Set(value As String)
            _MiddleName = value
            OnPropertyChanged(New PropertyChangedEventArgs("MiddleName"))
        End Set
    End Property
 
    Public Property Sex As String Implements IPerson.Sex
        Get
            Return _sex
        End Get
        Set(value As String)
            _sex = value
            OnPropertyChanged(New PropertyChangedEventArgs("Sex"))
        End Set
    End Property
#End Region
 
#Region "Methods"
    Public Sub New(guid As Guid, Optional created As DateTime = Nothing, Optional modified As DateTime = Nothing)
        Me._guid = guid
        Me._created = created
        Me._modified = modified
    End Sub
 
    Public Sub OnPropertyChanged(ByVal e As PropertyChangedEventArgs)
        If Not PropertyChangedEvent Is Nothing Then
            RaiseEvent PropertyChanged(Me, e)
        End If
    End Sub
#End Region
When the window is loaded it calls the following method to pull the information from a MySQL database:
Public Shared Function GetAllEmployees() As ObservableCollection(Of Employee)
        Dim connection As New MySqlConnection(connectionString)
        Dim command As New MySqlCommand
        command.Connection = connection
        command.CommandText = StoredProcedures.GetProcedureName(StoredProceduresEnum.GET_ALL_EMPLOYEES)
        command.CommandType = CommandType.StoredProcedure
 
        Dim ds As New DataSet
        Dim adapter As New MySqlDataAdapter
        adapter.SelectCommand = command
        adapter.Fill(ds)
 
        Dim employees As New ObservableCollection(Of Employee)
        Dim employee As Employee
 
        For Each row As DataRow In ds.Tables(0).Rows
            employee = New Employee(New Guid)
            With employee
                'TODO: Finish setting properties
                .FirstName = row.Item("FirstName").ToString
                .MiddleName = row.Item("MiddleName").ToString
                .LastName = row.Item("LastName").ToString
                .Sex = row.Item("Sex").ToString
                .IDNumber = row.Item("IDNumber").ToString
 
                employees.Add(employee)
            End With
        Next
        Return employees
    End Function
*Note that employee inherits from the Person class
 
When the information is done loading from the database I display it in the list box by using lstEmployees.ItemsSource = employees
 
My XAML (stripped down) is this:
<ListBox Name="lstEmployees" Grid.Column="0" Grid.RowSpan="2" MinWidth="150" Margin="5,5,5,5" VirtualizingPanel.IsVirtualizing="True" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border Margin="5" BorderThickness="1" BorderBrush="SteelBlue" CornerRadius="4">
                        <Grid Margin="3">
                            <Grid.RowDefinitions>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <TextBlock FontWeight="Bold">
                                <TextBlock.Text>
                                    <MultiBinding StringFormat=" {0}, {1} ">
                                        <Binding Path="LastName" />
                                        <Binding Path="FirstName" />
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                            <TextBlock Grid.Row="1">
                                <TextBlock.Text>
                                    <MultiBinding StringFormat="ID: {0}">
                                        <Binding Path="IDNumber" />
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                        </Grid>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
 
        <Grid x:Name="entryFieldsGrid" Grid.Column="2" Margin="5,5,5,5" Width="Auto" DataContext="{Binding ElementName=lstEmployees, Path=SelectedItem}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal" Grid.Row="0" >
                <TextBlock Text="First Name:" Padding="0,0,5,0" />
                <TextBox x:Name="firstName" Width="150" Text="{Binding Path=FirstName}"/>
                <TextBlock Text="Middle Name:" Padding="5,0,5,0"/>
                <TextBox x:Name="middleName" Width="150" Text="{Binding Path=MiddleName}"/>
                <TextBlock Text="Last Name:" Padding="5,0,5,0"/>
                <TextBox x:Name="lastName" Width="150" Text="{Binding Path=LastName}"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="1">
                <TextBlock Text="Sex:" Padding="0,0,5,0" />
                <ComboBox x:Name="cboSex" IsEditable="False" SelectedValue="{Binding Path=Sex}" DisplayMemberPath="Sex" SelectedValuePath="Sex">
                    
                </ComboBox>
            </StackPanel>
        </Grid>
 
As of now, when I select different employees in the list box, the three name boxes show the appropriate data, however the combo box doesn't show anything. I also had tried adding:
<ComboBoxItem></ComboBoxItem>
<ComboBoxItem>M</ComboBoxItem>
<ComboBoxItem>F</ComboBoxItem>
to the combo box in the hopes that it would select the correct item based on the currently selected employee and that the user would have the ability to change it to one of the supplied values to persists back to the database. However no matter how I change the binding properties, I can not get the combo box to show anything. Whether I have the combo box item elements in the XAML or not, the combo box never shows anything.
 
What am I doing wrong? Why won't the combo box select the correct gender based upon the currently selected item in the list box?
AnswerRe: WPF Combo box not display bound valuememberAmitosh Swain2-Jun-13 15:43 
DisIsHoody wrote:
<ComboBox x:Name="cboSex" IsEditable="False" SelectedValue="{Binding Path=Sex}" DisplayMemberPath="Sex" SelectedValuePath="Sex">

 
Remove all DisplayMemberPath & SelectedvaluePath. Binding For SelectedValue should be in TwoWay mode.
AnswerRe: WPF Combo box not display bound valueprofessionalMycroft Holmes2-Jun-13 20:12 
Your combo needs an ItemsSource (observable collection of m/f/o) if you use an object then you need the display and value paths otherwise Amitosh is also correct, SelectedValue needs Mode="TwoWay" to store it back to your SelectedItem.
Never underestimate the power of human stupidity
RAH

QuestionMessage Automatically Removedgroupzhangjinfu29-May-13 15:43 
Message Automatically Removed
QuestionSuggestions for Email HandlingmemberMehGerbil28-May-13 9:07 
I've a Silverlight application that manages the movement of electronic documents through a series of approval steps. When an approval step is complete I want the application to email the next user in the approval chain that work needs to be accomplished. I cannot depend upon all users logging into the application every day so the email reminders will help those who don't do much in the system.
 
I can send email from the application with no problems, but again, this is dependent upon the application being opened.
 
So I'm thinking it is probably best to put a Windows Service or something out on the server that automatically checks the state of the application every 5 minutes or so and handles the email. The point is, I'm open to suggestions.
 
I think this is something that needs to run off on it's own, separate from the Silverlight UI.
Thoughts, ideas, suggestions?
AnswerRe: Suggestions for Email HandlingprofessionalMycroft Holmes28-May-13 14:28 
I hate workflow application having just delivered 2 of the bloody things!
 
We used a combination of 2 email sources, instant where the app initiates the default email client (outlook) using the mailto. This is very limited but works for unformatted in your face NOW emails. This also allows the user to tinker with the message.
 
Scheduled reports from reporting services delivered daily via email. These are nicely formatted and carry a lot more information.
 
Rather than a windows service I would use a SQL Server job and send the emails from the database.
Never underestimate the power of human stupidity
RAH

QuestionBinding Enum to a ComboBoxprofessionalKenneth Haugland28-May-13 7:05 
Before I start the actual question I do know about these articles:
Fill Combobox With Sorted Enum Without Code[^]
Binding and Using Friendly Enums in WPF[^]
Funky WPF - Enumerations and Combo Boxes[^]
Enum to ComboBox binding[^]
 
However what I want to do is the folloing. Assume a Class that has an Enum as a Property:
Class Test
    Public Enum Something As Integer
        <Description("Something happended")> Something
        <Description("Nothing happended")> Nothing_
    End Enum
 
    Private pEnumer As Something = -1
    Public Property Enumer() As Something
        Get
            Return pEnumer
        End Get
        Set(ByVal value As Something)
            pEnumer = value
        End Set
    End Property
End Class
 
And now I want to bind a ComboBox to the Property Enumer, and I thought It would be simple to make an own based on the original ComboBox:
Public Class EnumComboBox
        Inherits ComboBox
 
        Private _EnumList As New List(Of EnumerationMember)
 
        Private pEnumItemsSorce As [Enum]
        Public Property EnumItemsSorce() As [Enum]
            Get
                Return pEnumItemsSorce
            End Get
            Set(ByVal value As [Enum])
                pEnumItemsSorce = value
                Me.ItemsSource = [Enum].GetValues(value.GetType)
 
            End Set
        End Property
 

        Public Function GetEnumItemSource(obj As DependencyObject) As [Enum]
            Return EnumItemsSorce
        End Function
 
        Public Sub SetEnumItemSource(obj As DependencyObject, value As [Enum])
            EnumItemsSorce = value
        End Sub
 
        ' Using a DependencyProperty as the backing store for Enum.  This enables animation, styling, binding, etc...
        Public Shared ReadOnly EnumItemSourceProperty As DependencyProperty = DependencyProperty.RegisterAttached("EnumItemSource", GetType([Enum]), GetType(EnumComboBox), New PropertyMetadata(Nothing, AddressOf OnEnumItemSourceChanged))
 
        Private Shared Sub OnEnumItemSourceChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
            Dim control = TryCast(sender, ItemsControl)
 
            If control IsNot Nothing Then
                If e.NewValue IsNot Nothing Then
                    Dim _enum = [Enum].GetValues(TryCast(e.NewValue, Type))
                    control.ItemsSource = _enum
                End If
            End If
        End Sub
 
        Protected Overrides Sub OnItemContainerStyleSelectorChanged(oldItemContainerStyleSelector As System.Windows.Controls.StyleSelector, newItemContainerStyleSelector As System.Windows.Controls.StyleSelector)
            MyBase.OnItemContainerStyleSelectorChanged(oldItemContainerStyleSelector, newItemContainerStyleSelector)
        End Sub
 
        Protected Overrides Sub OnSelectionChanged(e As System.Windows.Controls.SelectionChangedEventArgs)
            MyBase.OnSelectionChanged(e)
        End Sub
 
        Private _enumType As Type
 
        Private Sub GetValues(ByVal E As [Enum])
            Dim result As New List(Of String)
 
            Dim _enumType As Type
            _enumType = E.GetType
            Dim enumValues = [Enum].GetValues(_enumType)
 
            Dim f = (From enumValue In enumValues Select New EnumerationMember() With { _
              .Value = enumValue, _
              .Description = enumValue.GetDescription(enumValue) _
            }).ToList
 
            _EnumList = f
        End Sub
 
        Private Function GetDescription(enumValue As Object) As String
            Dim descriptionAttribute = TryCast(_enumType.GetField(enumValue.ToString()).GetCustomAttributes(GetType(ComponentModel.DescriptionAttribute), False).FirstOrDefault(), ComponentModel.DescriptionAttribute)
            Return If(descriptionAttribute IsNot Nothing, descriptionAttribute.Description, enumValue.ToString())
        End Function
 
        Public Class EnumerationMember
            Public Property Description() As String
                Get
                    Return m_Description
                End Get
                Set(value As String)
                    m_Description = value
                End Set
            End Property
            Private m_Description As String
            Public Property Value() As Object
                Get
                    Return m_Value
                End Get
                Set(value As Object)
                    m_Value = value
                End Set
            End Property
            Private m_Value As Object
        End Class
 
    End Class
 
The Idea is to bind the Enum property "Something" dire3ctly to the combobox, mewaning when I change the combobox index the property in the Test class also changes.
 

Question is: How can I alter the code above to make this happen?
AnswerRe: Binding Enum to a ComboBoxprofessionalMycroft Holmes28-May-13 14:22 
Kenneth Haugland wrote:
mewaning when I change the combobox index the property in the Test class also changes

Ignoring the detail of the rest of your question, I nearly went cross eyed reading VB as it has been so long, this seems to indicate the issue is in your combo binding. Are yo binding your combo to the datacontext in xaml where you should be setting either the SelectedItem or the SelectedValue and the Mode to TwoWay to drive the change in the ViewModel.
 
Or am I missing something?
Never underestimate the power of human stupidity
RAH

GeneralRe: Binding Enum to a ComboBoxprofessionalKenneth Haugland28-May-13 14:26 
Yes I can do that, but that would soon get messy, and I dont really like it (but it works). So I thought I could make a control that could do all of that without any XAML, just by creating a new Control that inherits the ComboBox.
GeneralRe: Binding Enum to a ComboBoxprofessionalMycroft Holmes28-May-13 14:33 
Kenneth Haugland wrote:
without any XAML

Wat, are you nuts, one of the main benefits of SL/WPF is the xaml binding of the data. I've heard of roll your own (I'm a great believer in it) but that is taking it way too far.
Never underestimate the power of human stupidity
RAH

GeneralRe: Binding Enum to a ComboBoxprofessionalKenneth Haugland28-May-13 14:35 
Ehhmm... I meant without cluttering up the XAML, not without it Laugh | :laugh:
GeneralRe: Binding Enum to a ComboBoxprofessionalMycroft Holmes28-May-13 14:50 
Ahh good, you were about to be consigned to the nether regions of...
 
Even so using the SelectedValue/SelectedItem are part of the core binding strategy. Binding to an ENUM on the other hand must have been a challenge and it looks like it "cluttered" up your code somewhat! So is the selection changing your core issue here.
Never underestimate the power of human stupidity
RAH

GeneralRe: Binding Enum to a ComboBoxprofessionalKenneth Haugland28-May-13 15:46 
Yes actually, sort of, the values in the combobox stems from the Description of the Enum's and not the enum itself. I actually want to know how do you tell the property in the class, that the selection in hte combobox has change, so you should now update the property.
QuestionRe: Binding Enum to a ComboBoxprofessionalKenneth Haugland29-May-13 7:53 
I got it working but I had to do thius:
Private Sub cmbEnumComboBox_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) Handles cmbEnumComboBox.SelectionChanged
    t.Enumer = cmbEnumComboBox.EnumItemsSorce
End Sub
 
Now I know that is stupid, how could I do this without this, any ideas?
AnswerRe: Binding Enum to a ComboBoxprofessionalKenneth Haugland31-May-13 21:05 
I found a solution, so now I can bind an Enum property to a custom combobox without any clutter in Code behind or XAML:
Imports System.ComponentModel
 
Namespace WPF
    Public Class COmboBoxAttached
        Inherits ComboBox
 
        Private _EnumList As New List(Of EnumerationMember)
 
        Private DontRebind As Boolean = False
 
        Private pEnumItemsSorce As [Enum]
        Public Property EnumItemsSorce() As [Enum]
            Get
                Return pEnumItemsSorce
            End Get
            Set(value As [Enum])
                If Not DontRebind Then
                    GetValues(value)
                    Me.ItemsSource = _EnumList
                    Me.DisplayMemberPath = "Description"
                    Me.SelectedValue = "Value"
                End If
 
                DontRebind = False
                pEnumItemsSorce = value
            End Set
        End Property
 
        Protected Overrides Sub OnSelectionChanged(e As System.Windows.Controls.SelectionChangedEventArgs)
 
            If Me.SelectedValue IsNot Nothing Then
                DontRebind = True
                EnumItemsSorce = DirectCast(Me.SelectedValue, EnumerationMember).Value
            End If
 
            MyBase.OnSelectionChanged(e)
        End Sub
 
        Private _enumType As Type
 
        Private Sub GetValues(ByVal E As [Enum])
            Dim result As New List(Of String)
 
            Dim _enumType As Type
            _enumType = E.GetType
            Dim enumValues = [Enum].GetValues(_enumType)
 
            Dim f = (From enumValue In enumValues Select New EnumerationMember() With { _
              .Value = enumValue, _
              .Description = DirectCast(enumValue, [Enum]).GetDescription _
            }).ToList
 
            _EnumList = f
        End Sub
 
        Private Function GetDescription(enumValue As Object) As String
            Dim descriptionAttribute = TryCast(_enumType.GetField(enumValue.ToString()).GetCustomAttributes(GetType(ComponentModel.DescriptionAttribute), False).FirstOrDefault(), ComponentModel.DescriptionAttribute)
            Return If(descriptionAttribute IsNot Nothing, descriptionAttribute.Description, enumValue.ToString())
        End Function
 
        Public Class EnumerationMember
 
            Public Property Description() As String
                Get
                    Return m_Description
                End Get
                Set(value As String)
                    m_Description = value
                End Set
            End Property
            Private m_Description As String
            Public Property Value() As Object
                Get
                    Return m_Value
                End Get
                Set(value As Object)
                    m_Value = value
                End Set
            End Property
            Private m_Value As Object
        End Class
    End Class
End Namespace

QuestionData binding problemmembercolumbos1492728-May-13 3:12 
Hello,
I have a Window and a viewModel class as a data context of the window.
When i try to change some variables in the viewModel class that are binded to Window properties.
I get the next exception:
"Cannot use a DependencyObject that belongs to a different thread than its parent Freezable".
 
I know that in WPF you dont have access to a UI elements properties from other threads but here i dont directly access the UI element properties i access some variables that are binded to them.
 
how can i solve this?
AnswerRe: Data binding problemmvpAbhinav S28-May-13 3:58 
Make sure you are accessing the UI / properties on the right thread.

QuestionNeed suggestion on application architecture.memberBeniston120528-May-13 0:05 
Hi Everybody,
 
Good Day.
 
Am gonna develop an windows based application in WPF like holding employee profile. It will save the data and also it will have employee image and his/hers parents image. i am using backedn server as SQL and the SQL server is centralized and i will be accessing through internet.
 
Now i want suggestion that where should i save my images? is it ok to save in image data type of DB server?
 
or do i need to use any common folder file systems? if as this is an windows application do i need to give any persmissions? so that it will be accessible from windows app?
 

or is it possible to use google picasa or anything like that? and will it have any licencing issue if i market the application?
 

 
please suggest me the best way to save the images from windows application?
 
thanks in advance.
AnswerRe: Need suggestion on application architecture.mvpAbhinav S28-May-13 3:57 
If you are using Silverlight, you will not be able to access the file system folder without elevated permissions.
Thus it will be easier for you to store images on the DB server using a web service.

GeneralRe: Need suggestion on application architecture.memberBeniston120528-May-13 20:14 
Dear Abinav,
 
Thanks for your reply
 
When you say to store images in database and use web service?
 
will image will transfer fast in web service? and how to send image via webservice?
or will it work through ADO.NET via internet?
 
which will be faster?
 
thanks in advance/
AnswerRe: Need suggestion on application architecture.memberSledgeHammer0128-May-13 6:56 
Store everything in the DB. Do you really want a file share open to the internet? Smile | :)
GeneralRe: Need suggestion on application architecture.memberBeniston120528-May-13 20:14 
Dear Hammer,
 
THanks for your response. I have some questions on this which i have posted in the above reply.
 
thanks

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web04 | 2.6.130617.1 | Last Updated 19 Jun 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid