Click here to Skip to main content
15,891,184 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Error in capturing Images and Video in same form Pin
Manch Manj9-Jul-08 20:31
Manch Manj9-Jul-08 20:31 
QuestionShow 3d-mediatype in wpf [modified] Pin
hmshmsm8-Jul-08 1:41
hmshmsm8-Jul-08 1:41 
Questionwpf command parameters Pin
cechode7-Jul-08 9:34
cechode7-Jul-08 9:34 
AnswerRe: wpf command parameters Pin
Gideon Engelberth9-Jul-08 5:06
Gideon Engelberth9-Jul-08 5:06 
QuestionBind Objects to ListView / Grid where Objects hold their Position in Grid [modified] Pin
ezazazel7-Jul-08 4:33
ezazazel7-Jul-08 4:33 
AnswerRe: Bind Objects to ListView / Grid where Objects hold their Position in Grid Pin
Gideon Engelberth9-Jul-08 5:14
Gideon Engelberth9-Jul-08 5:14 
GeneralRe: Bind Objects to ListView / Grid where Objects hold their Position in Grid Pin
ezazazel9-Jul-08 8:51
ezazazel9-Jul-08 8:51 
GeneralRe: Bind Objects to ListView / Grid where Objects hold their Position in Grid Pin
Gideon Engelberth9-Jul-08 12:51
Gideon Engelberth9-Jul-08 12:51 
I'm not sure why you would need to inherit MatrixElement from TextBlock. For this post, I'll keep the MatrixElement as just a regular class with the properties in your original post. I also ignored the background, because depending on how the background is created in the first case, you may be better off using a trigger. Here's the markup for the window:

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfTrash"
    Title="Window1" Height="400" Width="600">
    <Window.Resources>
        <DataTemplate DataType="{x:Type local:MatrixElement}">
            <TextBlock Text="{Binding Text}" 
                       ToolTip="{Binding ToolTip}"
                       HorizontalAlignment="Center" />
        </DataTemplate>
    </Window.Resources>
    <ListBox Name="lstItems" Background="Green">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <Grid Name="grdTest"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemContainerStyle>
            <Style TargetType="{x:Type ListBoxItem}">
                <Setter Property="Grid.Row" 
                        Value="{Binding Content.PositionX, 
                                        RelativeSource={RelativeSource Self}}" />
                <Setter Property="Grid.Column" 
                        Value="{Binding Content.PositionY, 
                                        RelativeSource={RelativeSource Self}}" />
            </Style>
        </ListBox.ItemContainerStyle>
    </ListBox>
</Window>


And the code behind (in VB):

Class Window1 

    Private Sub Window1_Loaded(ByVal sender As Object, _
                               ByVal e As System.Windows.RoutedEventArgs) _
                               Handles Me.Loaded
        'create some dummy elements and set the items source of the listbox
        Dim elems As New List(Of MatrixElement)
        Dim curElem As MatrixElement
        For r As Integer = 0 To 63
            curElem = New MatrixElement
            curElem.PositionX = r
            curElem.PositionY = r
            curElem.Text = String.Format("{0}, {0}", r)
            elems.Add(curElem)
        Next
        lstItems.ItemsSource = elems

        'finds the actual grid used by the list box
        Dim d As DependencyObject
        d = VisualTreeHelper.GetParent( _
                lstItems.ItemContainerGenerator.ContainerFromIndex(0))
        While Not (d Is Nothing OrElse d.GetType() Is GetType(Grid))
            d = VisualTreeHelper.GetParent(d)
        End While
        If d Is Nothing Then Exit Sub

        'once you have the grid, you need to add the rows and columns
        Dim rd As RowDefinition
        Dim cd As ColumnDefinition
        Dim grd As Grid = CType(d, Grid)
        lstItems.SetValue(Grid.IsSharedSizeScopeProperty, True)
        For i As Integer = 0 To 63
            rd = New RowDefinition
            rd.Height = New GridLength(1, GridUnitType.Star)
            rd.SharedSizeGroup = "MatrixElemRowGroup"
            grd.RowDefinitions.Add(rd)
            cd = New ColumnDefinition
            cd.Width = New GridLength(1, GridUnitType.Star)
            cd.SharedSizeGroup = "MatrixElemColumnGroup"
            grd.ColumnDefinitions.Add(cd)
        Next
        'this is just for debugging purposes
        grd.ShowGridLines = True
    End Sub

End Class

GeneralRe: Bind Objects to ListView / Grid where Objects hold their Position in Grid Pin
ezazazel10-Jul-08 1:15
ezazazel10-Jul-08 1:15 
GeneralRe: Bind Objects to ListView / Grid where Objects hold their Position in Grid Pin
Gideon Engelberth10-Jul-08 3:25
Gideon Engelberth10-Jul-08 3:25 
QuestionrichTextbox to HTML ? [modified] Pin
Mohammad Dayyan5-Jul-08 14:27
Mohammad Dayyan5-Jul-08 14:27 
AnswerRe: richTextbox to HTML ? Pin
Pete O'Hanlon6-Jul-08 4:00
mvePete O'Hanlon6-Jul-08 4:00 
QuestionShow CHM Help File Pin
Jammer5-Jul-08 10:49
Jammer5-Jul-08 10:49 
AnswerRe: Show CHM Help File Pin
Pete O'Hanlon6-Jul-08 8:50
mvePete O'Hanlon6-Jul-08 8:50 
GeneralRe: Show CHM Help File Pin
Jammer6-Jul-08 13:14
Jammer6-Jul-08 13:14 
GeneralRe: Show CHM Help File Pin
Krishnraj31-Jul-08 19:38
Krishnraj31-Jul-08 19:38 
QuestionHandle return(ENTER) pressing on richTextBox in WPF ? [modified] Pin
Mohammad Dayyan4-Jul-08 3:50
Mohammad Dayyan4-Jul-08 3:50 
AnswerRe: Handle return(ENTER) pressing on richTextBox in WPF ? Pin
Pete O'Hanlon4-Jul-08 9:41
mvePete O'Hanlon4-Jul-08 9:41 
GeneralRe: Handle return(ENTER) pressing on richTextBox in WPF ? Pin
Mohammad Dayyan4-Jul-08 9:47
Mohammad Dayyan4-Jul-08 9:47 
GeneralRe: Handle return(ENTER) pressing on richTextBox in WPF ? Pin
Pete O'Hanlon4-Jul-08 10:05
mvePete O'Hanlon4-Jul-08 10:05 
GeneralRe: Handle return(ENTER) pressing on richTextBox in WPF ? Pin
Mohammad Dayyan4-Jul-08 10:19
Mohammad Dayyan4-Jul-08 10:19 
QuestionSilverLight beta 2 Pin
Member 39206674-Jul-08 1:17
Member 39206674-Jul-08 1:17 
AnswerRe: SilverLight beta 2 Pin
Michael Sync4-Jul-08 20:13
Michael Sync4-Jul-08 20:13 
GeneralRe: SilverLight beta 2 Pin
Member 39206676-Jul-08 19:42
Member 39206676-Jul-08 19:42 
GeneralRe: SilverLight beta 2 Pin
Michael Sync6-Jul-08 20:25
Michael Sync6-Jul-08 20:25 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.