Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all 18858 articles
Browse latest View live

Master-detail GridView, Does anyone have one sample?

$
0
0

Hi, my goal is just connect two Sql tables in my couple of Gridview.

I'm using third-vendor stuff but concepts here will be welcomed anyway for any kind of control.

So, does anyone have any Master-detail RadGridView (I've got 4.5 Framework version on WPF projects) or typical GridView available?

I'm populating them using code-behind classic ADO stuff. I know that it is a bit old-fashioned way to work but I am in a hurry and I reallly need to get some solution:


Here you have my xaml declaration:


 <telerik:RadGridView x:Name="dgvUsuarios" ItemsSource="{Bindingv_empleados}" HorizontalAlignment="Left"
            Margin="10,44,0,0" VerticalAlignment="Top" Height="217"             Width="469" ColumnWidth="SizeToCells"
                             AutoGenerateColumns="False"
                             PreviewMouseDoubleClick="dgvUsuarios_PreviewMouseDoubleClick" Grid.ColumnSpan="2" Grid.RowSpan="2">

code-behind:

        Dim connexio As SqlConnection
        Dim ada As New SqlDataAdapter()
        Dim ds As New DataSet
        Dim sSql As String = "SELECT * FROM v_empleados"


       connexio = New SqlConnection("Server='ENRIC-PC\ENRIC';Initial Catalog=Talleres;User ID=usrTalleres;Password=cesarenric;current language=spanish")

        connexio.Open()

        ada = New SqlDataAdapter(sSql, connexio)
        ada.Fill(ds, "v_empleados")
        Me.dgvUsuarios.DataContext = ds


Thanks in advance for your help,

Enric


Primary platform is Windows 7 Ultimate 64 bit along with VS 2012/Sql2k8 for WPF/SilverLight projects.


Batch printing of Visuals to Xps leads to OutOfMemoryException

$
0
0

Hi,

I am printing to xps in this way:

PrintQueue queue = printQueueObject as PrintQueue;

if (queue != null)
{
    queue.Refresh();
    collator = PrintQueue.CreateXpsDocumentWriter(queue).CreateVisualsCollator();
    collator.BeginBatchWrite();

    ...
    collator.Write(visual);
    collator.EndBatchWrite();
}

After 1000 pages or so are printed, I get an OutOfMemoryException. After using a memory profiler, the problem source seems to be the following chain:

InterleavingNode

-> System.Windows.Xps.Packaging.XpsFixedPageReaderWriter
-> _parentNode (field)
--> XpsFixedDocumentReaderWriter
--> _pageCache (field of type List<IXpsFixedPageReader>)

---> 800 instances of XpsFixedPageReaderWriter

-----> 2400 instances of System.IO.StringWriter = 2400 instances of System.Text.StringBuilder

or in other words:

There seems to be a page cache that is growing all the time, while we are generating the XPS document. So if we generate a huge document with many thousands of pages we get sooner or later an OutOfMemoryException (depending on the users available memory).

There has been a similar question here:

https://connect.microsoft.com/VisualStudio/feedback/details/788507/creating-xps-document-with-visuals-collator-consumes-a-very-large-amount-of-memory

But there has never been a solution or workaround to this. I am currently using Windows 8.

Thanks





how to navigate from one WPF form to another?????

$
0
0

hi,

i created a project in c# and added the wpf windows in the expression blend 4. After adding these windows what all that i can see in the solution explorer are the Window_name.xaml files. now i have created a button in the MainWindow.xaml window, now i want to navigate form this WPF window to the another WPF window named as Window2.xaml on the button click.

can any one suggest me the possible code in c# ??????

 

 

Filtering through multiple ListView WPF

$
0
0


I am creating an application that consists of multiple patterns and frameworks which include, MVVM, Singleton pattern and entity framework within one WPF application.

My application consists of two aspects; A School and a Course. Due to the use of the singleton pattern, I have the following ViewModels; 

SchoolListVM -> SchoolVM -> CourseVm

I am trying to implement a simple `filter` to enable a user to search through a listview within my view, shown below.



As you can see, I have a filter to search through a the list of Schools and currently trying to implement a filter to search through the list of courses; but this is where my problem lies. 

I have been following this link here to help me implement a filter and changed it to suit the needs of my application.

However, when I implement this I get two problems: 

The first issue is when I bind my ObservableCollection to the ItemSource within my view (for the course list), nothing seems to display. 

The second issue is that get the following error;

Object reference not set to an instance of an object.

This is produced when I call View.Refresh();

I have put together a sample application to represent my problem that I encounter, which can be found here - ListviewSearch

Could anyone please help me in trying to solve this issue?

Many thanks in advance.


Glow effect on Tab Item

$
0
0

I am working on custon tabs in wpf. So far I am able to do

<Grid Background="#2B3C59"><TabControl Margin="10" BorderThickness="0, 3, 0, 0" BorderBrush="#FFE8A6" Background="#D3D3D3"><TabControl.Resources><Style TargetType="TabItem"><Setter Property="Height" Value="30"/><Setter Property="MinWidth" Value="40"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="TabItem"><Border Name="Panel"
                                        Padding="10, 0, 10, 0" CornerRadius="2, 2, 0, 0"><ContentPresenter x:Name="ContentSite"
                                        VerticalAlignment="Center"
                                        HorizontalAlignment="Center"
                                        ContentSource="Header"/></Border><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter TargetName="Panel" Property="Opacity" Value="0.5"/><Setter TargetName="Panel" Property="Background" Value="White"/><Setter TargetName="Panel" Property="BorderThickness" Value="1, 1, 1, 0"/><Setter TargetName="Panel" Property="BorderBrush" Value="WhiteSmoke"/></Trigger><Trigger Property="IsSelected" Value="True"><Setter TargetName="Panel" Property="BorderThickness" Value="0"/><Setter TargetName="Panel" Property="Background" Value="#FFE8A6" /><Setter TargetName="Panel" Property="Opacity" Value="1.0"/></Trigger><!--Trigger Property="IsSelected" Value="False"><Setter Property="TextElement.Foreground" Value="White" /></Trigger--></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style></TabControl.Resources><TabItem Header="General"><Label Content="Tab 1" /></TabItem><TabItem Header="Tab 2" /><TabItem Header="Tab 3" /></TabControl></Grid>

but i want to have glow effect like in Visual studio when mouse hovered on a tab:

OuterGlowBitmapEffect does not seem to work now in .net 4.0

Any help? Thanks in advance.

TextTrimming not working on WPF TextBlock

$
0
0

Hi,

TextTrimming is not working as expected and I am not getting ... following my text. Please note, I don't want to give fix width of TextBLock

<ColumnDefinition x:Uid="ColumnDefinition_2" Width="140"/>

...

...

...

<StackPanel ...><Image ... /><TextBlock ToolTip="{Binding MyTooltip}"><TextBlock Name="MyName" Text="Really a long text to test given scenario" VerticalAlignment="Top" Height="auto" HorizontalAlignment="Left" TextTrimming="CharacterEllipsis" ></TextBlock></TextBlock></StackPanel>



Regards, http://www.shwetalodha.blogspot.in/


How to bind two DataGrid DataGridBoundColumn to the same source

$
0
0

In Visual Studio 2010 / .NET Framework 4.0 I would like to bind two DataGridBoundColumn in a single DataGrid to the same data source (DataSet).

The frist column should be used for editing the value, the second column should be ReadOnly and display additional information (by use of a ValueConverter) upon PropertyChanged or LostFocus on the first column.

Unfortunately in my code the second column is not refreshing unless I forcibly refresh the ItemsSource of the DataGrid.

To reproduce the problem in VisualStudio 2010 follow these steps:

  • Create a new WPF application called BindingTest
  • Change .NET Framework to 4.0
  • Create a class ViewModel using the following code:
    using System;
    using System.Data;
    namespace BindingTest
    {publicclassViewModel
    {
    DataSet _DataSet;

    public
    ViewModel()
    {
    _DataSet =newDataSet();

    var
    dataTable = new DataTable();
    dataTable.Columns.Add("ID",typeof(int));
    dataTable.Columns[0].AutoIncrement =true;
    dataTable.Columns[0].AllowDBNull =false;
    dataTable.Columns.Add("Text",typeof(string));           

    _DataSet.Tables.Add(dataTable);
       }

        publicDataView MyData
        {
        get {return _DataSet.Tables[0].DefaultView; }
        }
        }
        }
  • Creat a new window MainWindow
  • Replace the content of MainWindo.xaml with the following:
    <Window x:Class="BindingTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:BindingTest"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
    <Grid.RowDefinitions>
    <RowDefinition/>
    <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid.DataContext>
    <local:ViewModel />
    </Grid.DataContext><DataGrid Grid.Row="0" Margin="2" Name="MyDataGrid" AutoGenerateColumns="False"CanUserAddRows="True" CanUserDeleteRows="True" ItemsSource="{Binding MyData}">
    <DataGrid.Columns>
    <DataGridTextColumn Header="ID"IsReadOnly="True" Binding="{Binding ID, Mode=OneWay}"/>
    <DataGridTextColumn Header="Text" Binding="{Binding Text}"/>
    <DataGridTextColumn Header="Text (R/O)" IsReadOnly="True" Binding="{Binding Text, Mode=OneWay}"/>
    </DataGrid.Columns>
    </DataGrid>
    <StackPanel Grid.Row="1" Orientation="Horizontal">
    <Button Margin="2" Name="RefreshButton" Click="RefreshButton_Click">Refresh</Button>
    </StackPanel>
    </Grid>
    </Window>
  • Replace the content of MainWindow.xaml.cs with the following:
    using System;
    using System.Windows;
    namespace BindingTest
    {
    ///<summary>
    /// Interaction logic for MainWindow.xaml
    ///</summary>
    publicpartialclass MainWindow : Window
    {
    public MainWindow()
    {
    InitializeComponent();
    }
    privatevoid RefreshButton_Click(object sender,RoutedEventArgs e)
    {
    MyDataGrid.Items.Refresh();
    }
    }
    }
  • Compile and run the application
  • Enter a string into column 1:
  • Tab off the grid to update the DataSet.The second column will not immediately update:
  • Press "Refresh" to force refreshing the DataGrid

Anticipative thanks and kind regards

-- 
Sebastian Daser
Softfount IT Solutions

Baumweg 16
60316 Frankfurt
Telefon +49-171-5853738

USt.-Nr. 012 811 08436

Popup Child window content not rendering

$
0
0

I need to display some message to user untill it is refreshes content from database. i decided to open one  modalwindow which will display Refreshing... message to user.

i am putting following code in a function and once tasks completes i am closing that window but i am getting blank window. how i can render popup content

myfunction(){

var w=new Window();

w.content="Refreshing";

w.show();

return w;

}

main()

{

var w=myfunction();

dowork();

w.close();

}


F a i r L i g h t


Clipboard No data with FileDrop from Local -> Remote

$
0
0

I havewritten a programthatretrievesdatafrom the clipboard. But I have a problem when I copy a (or multiple) Image-file(s) on my local system and use my application to catch the data from the clipboard (FileDrop). There is no data available.

So I tried multiple things:

  • Local -> Local
  • Remote -> Remote
  • Local -> Remote

When I local copy an image and use my application to catch the image (local) it proceeds (Clipboard.ContainsImage()).

When I local copy a file and use my application to catch the file (local) it proceeds (Clipboard.ContainsFileDropList()).

When I Remote copy an image and use my application to catch the image (Remote ) it proceeds (Clipboard.ContainsImage()).

When I Remote copy a file and use my application to catch the file (Remote ) it proceeds (Clipboard.ContainsFileDropList()).

When I local copy an image and use my application to catch the image (Remote ) it proceeds (Clipboard.ContainsImage()).

When I local copy a file and use my application to catch the file (Remote ) there is no data available(Clipboard.ContainsFileDropList()).

I also tried the sample application from Microsoft:

http://code.msdn.microsoft.com/CSWPFClipboardViewer-f601b815

But the same problem.

Hope someone can help me... But I think it is a bug in the Clipboard library!

 

DataGrid's ItemsSource as DataTable causes memory leaks?

$
0
0

Hello:

please review the project at https://github.com/jiripik/WpfDataTableMemoryLeaks and check out the memory before the DataTable's ItemsSource was assigned to a DataTable and after it was reset to null.

You will see that the allocated memory as measured by

GC.GetTotalMemory(true)

substantially increases.

If I use List or ObservableCollection, there is no such a memory increase.

Can you please advise if I miss something or whether there is truly a memory leak?


Jiri Pik, jiri@jiripik.com Web: http://jiripik.com, LinkedIn: http://www.linkedin.com/in/jiripik, Twitter: http://twitter.com/@JiriPik

Combobox in datagrid question - displaying a property of the combo in a textbox

$
0
0

I'd like to put a property of a combobox in a textbox on a datagrid.

Combo in a datagrid defined like so:

 

Xaml:

<DataGridTemplateColumn x:Name="cboPartBCPT" Header="CPT Code" Width="100" ><DataGridTemplateColumn.CellTemplate><DataTemplate><TextBlock Text="{Binding CPT}" /></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn.CellEditingTemplate ><DataTemplate><ComboBox x:Name="cboPartBCPT"
                                                ItemsSource="{Binding Source = {StaticResource PartB_CPTLookup}}"
                                                SelectedValue="{Binding Path=CPT}"
                                                SelectedValuePath="CPT"
                                                DisplayMemberPath="CPT"
                                                           IsSynchronizedWithCurrentItem="True"></ComboBox></DataTemplate></DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn><DataGridTextColumn x:Name="PartBProcedure" Header="Procedure" Width="200"
                                            Binding="{Binding SelectedItem.ProcedureName, ElementName=cboPartBCPT}" />

PartBProcedure is always blank. What am I doing wrong?


Thanks.

Question about sorting Detail table

$
0
0

Someone posted almost the exact same question here.  I attempted to use that answer in my situation but am not sure how to form the syntax.  I'm using WPF and EF.

I, too, have a master/detail situation that uses a combo box that fills a datagrid.  The combo is sorted by patient name.  I'd like the grid to sort by appointment date.

The EF wizard created the following code (I added the sort description).

        Dim TblPatientDemographicViewSource As System.Windows.Data.CollectionViewSource =
            CType(Me.FindResource("TblPatientDemographicViewSource"), System.Windows.Data.CollectionViewSource)

        'sort view by patient name.  
        TblPatientDemographicViewSource.SortDescriptions.Add(New SortDescription("PatientName", ListSortDirection.Ascending))

        'Load data by setting the CollectionViewSource.Source property:
        'TblPatientDemographicViewSource.Source = [generic data source]
        _context.tblPatientDemographics.Load()
        TblPatientDemographicViewSource.Source = _context.tblPatientDemographics.Local

The suggested answer (converted to vb.net from c#):

        DirectCast(TblDentistAppointmentsDataGrid.Items, ItemCollection).SortDescriptions.Add(New System.ComponentModel.SortDescription("DentistAppointmentDate", System.ComponentModel.ListSortDirection.Ascending))

I'm not sure where to place this suggested code in my code block.  More importantly, I'm not sure the syntax is correct.  Looking at the xaml, I noticed the resource name:

<DataGrid x:Name="TblDentistAppointmentsDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" 
                  ItemsSource="{Binding Source={StaticResource TblPatientDemographictblDentistAppointmentsViewSource}}" 
I thought maybe that resource is what I should apply the sort description to but that is not an option when forming the syntax. 

Thanks.


the calling thread must be sta because many ui components require

$
0
0

I want to show the animated progressbar while saving view
the above code is the one I'm experimenting on but it gives me an error saying:

" The calling thread must be STA, because many UI components require this."
The error appears on the constructor of the Page i'm loading.

I have no idea now what to do. Is there any way I can make this simpler as this is my frist time to use BackgroundWorker..

private void OnScreenShotAllCommandExecuted(object parameter) { UserControl view = new UserControl();

view.Show(); SaveAllScreen saveScerrn = new SaveAllScreen(); worker.RunWorkerAsync(saveScerrn); } private void worker_DoWork(object sender, DoWorkEventArgs e) { SaveAllScreen.OnScreenShotAllCommand(); if (worker.CancellationPending) { e.Cancel = true; return; } } private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { MessageBox.Show("Search cancelled."); } else if (e.Error != null) { // An error was thrown by the DoWork event handler. MessageBox.Show(e.Error.Message, "An Error Occurred"); } }


XML serialization List problem

$
0
0

Hey there,

I want to save custom classes to file, so I need to pass a serialization. Those classes are mostly of Canvas, Line stuff, so I need an XML Serialization.

I have a custom class:

class Kanvas
{
     Line l;
     Canvas c;
     double width;
     //... and so on
     public Kanvas()
     {
          c = new Canvas();
             // so on
     }
}

and I need to serialize a List<Kanvas> of those Kanvas objects.

Here's my serialization:

List<Kanvas> KK = new List<Kanvas>();

//filling KK with some Kanvas...

System.IO.FileStream filestream = new System.IO.FileStream("D:\\file.txt", System.IO.FileMode.Create);
XmlSerializer xm = new XmlSerializer(typeof(List<Kanvas>);
xm.Serialize(filestream, KK);
filestream.Close();

and I get an exception "There was an error reflecting type..." thrown. I did some searching and found that the problem is in line where XmlSerializer object is created. Maybe the typeof() ?

Please help!


Knowledge: C, C++, C#, Java, Pawn

Vector class explanation

$
0
0

Hey all, 

I need an explanation of Vectors in WPF. I just don't understand how is a vector defined here. In math, vectors have a direction (can be determined by angle) and value. In picture, here it is:

Could someone please explain me how this:

Vector vec = new Vector(10,10);
vec.Length // what is this???

looks like? And how to use it?

Please, in picture.


Knowledge: C, C++, C#, Java, Pawn


print chart to xps

$
0
0

hello,

i created a chart in a fixeddocument. i used clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit

i have a problem when i print the document. i used this code

        Dim fd As FixedDocument = stampa.FindName("myFixedDocument")
        Dim xpsd As Packaging.XpsDocument = New Packaging.XpsDocument("G:\test.xps", System.IO.FileAccess.ReadWrite)
        Dim xw As XpsDocumentWriter = Packaging.XpsDocument.CreateXpsDocumentWriter(xpsd)
        xw.Write(fd)
        xpsd.Close()

the file printed don't show the barchart. print all except bar.

can anyone help me?

thanks

Marco

RichTextBox serialization added "{}" when the first char in paragraph is "{"

$
0
0

namespace TestRichTextBox

{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string str = FlowDocumentToString(RichBox.Document);
            xamlStringBox.Text = str;

        }
        private string FlowDocumentToString(FlowDocument doc)
        {
            var settings = new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true };

            StringBuilder sb = new StringBuilder();
            var dm = new XamlDesignerSerializationManager(XmlWriter.Create(sb, settings));
            dm.XamlWriterMode = XamlWriterMode.Expression;

            XamlWriter.Save(doc, dm);

            return sb.ToString();
        }
    }
}

<Window x:Class="TestRichTextBox.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid HorizontalAlignment="Left" Height="300" VerticalAlignment="Top" Width="483" Grid.RowSpan="2" Margin="10,20,0,0">
            <TextBox Name="xamlStringBox" HorizontalAlignment="Left" Height="152" Margin="0,138,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="393"/>
            <Button Content="Button" HorizontalAlignment="Left" Margin="398,225,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
        </Grid>
        <RichTextBox Name="RichBox" HorizontalAlignment="Left" Height="127" Margin="10,10,0,0" VerticalAlignment="Top" Width="393">
            <FlowDocument>
                <Paragraph>
                    <Run Text=""/>
                </Paragraph>
            </FlowDocument>
        </RichTextBox>
    </Grid>
</Window>

Run the sample code and type { in the RichBox at first char, Click the button, the xamlStringBox will show the serialized FlowDocument.  The paragraph shows:

 <Paragraph>{}{</Paragraph>

Is this a bug? Is there any walk-around?

Thanks


Crystal Report failed after creating Setup of My Window Project

$
0
0

I have created a Windows Project Setup .

It runs properly.But When I want to open Crystal Reports."Report Load Failed" Error is coming

 

SurfaceKeyboard doesn't open in Win7

$
0
0

Hey there,

i'm trying to integrate the SurfaceKeyboard into an existing program but this causes some problems..
When I try to open the Keyboard with setting the IsVisible property to 'True' nothing happens.

System.Windows.Input.Keyboard.Focus((IInputElement)sender);
SurfaceKeyboard.IsVisible = true;

I found out that the value of the property didn't change, so it's still 'False'.

In this post: 

http://social.msdn.microsoft.com/Forums/vstudio/en-US/c460ed52-dbde-4540-868a-bce0f1a906d7/show-numeric-keypad-in-windows-7-wpf-touch-application?forum=wpf

i've read that it should be possible to use the SurfaceKeyboard also in Win7..

Can anyone help me with this issue?

Right now I have installed VS2010 with Surface SDK 2.0 and Surface Runtime 2.0.

Thanks in advance!

e_card

If i call Task.Dispose will the Task be canceled too???

$
0
0

Hey,

is it it enought to call Dispose on a Task to cancel it?? Or maybe the Task will finish before eleminated??


Viewing all 18858 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>