You will need to look into DirectShow SDK.
Encoding into H.264 is directly not possible, however there are commercial activex controls that can help you. But you need to understand few things,
DirectShow is audio/video processing framework, and you can use graph edit tool to put your devices on the graph and test it. And you have to write similar code to build graph, graph is chain of devices/objects that interact with each other to produce final output.
DirectShow can be used in .NET, you can use GraphEditPlus tool to create a graph and use it in .NET, however I doubt .NET is better way because it may lead to unknown errors as DirectShow is closely bound to COM. If you create ActiveX control, in native C++ and use DirectShow to do entire recording and you use ActiveX in WPF, that will be more stable however difficult to program.
Typically you will need graph as following,
Video Source => Demux -> Audio Stream + Video Stream -> MP4Muxer
x264 is free open source and has a good MP4Muxer but not legal, you must have patent licenses acquired for using H264 in your code.
Alternatives are you can go with lots of commercial controls, Intel's IPP is the best implementation of H264 so far, but its little tricky to put it in directshow.